using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TABS.MailCarrier.WebSDK.Approval;

public partial class Approval_RejectApproval : System.Web.UI.Page
{
    protected string _declineButtonText = Resources.Approval.Approval_Decline_Button;

    protected override void InitializeCulture()
    {
        string defLang = WebUser.CurrentUser.UiLanguage;
        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(defLang);
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(defLang);
        base.InitializeCulture();
    }

    protected void Page_Init(object sender, EventArgs e)
    {
        WebUtil.SetMcCommonCss(Page.Header);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Page.Title = AppSetting.GetTitleInfo(Request).Title;
            _declineButtonText = WebParam.GetStrParamValue("btext", Resources.Approval.Approval_Decline_Button);

            ApprovalPerson person = new ApprovalPerson(WebParam.GetGuidParamValue("person"));
            person.Load();
            RejectTextBox.Value = person.Reject;
        }
    }

    protected void RejectButton_Click(object sender, EventArgs e)
    {
        Guid personId = WebParam.GetGuidParamValue("person");
        string rejectDesc = RejectTextBox.Value;
        ApprovalPerson person = new ApprovalPerson(personId);
        person.Load();
        person.WebsiteAppUrl = WebParam.GetCurrentWebAppUrl();
        person.WebsiteAppUrl1 = AppSetting.GetTitleInfo(Request)["website1"];
        if (AppSetting.ApvCollaboration != 1)
        {
            person.SetStatusUpdate2(ApprovalPerson.AppStatus.Reject, rejectDesc, DateTime.UtcNow, AppSetting.RejectApprovalNotificationTemplateFile, "", 3);
        }
        else
        {
            person.SetStatusUpdate(ApprovalPerson.AppStatus.Reject, rejectDesc, DateTime.UtcNow, AppSetting.RejectApprovalNotificationTemplateFile, "", 3);
        }

        Response.Redirect("List.aspx?type=" + AppFolderDataSource.APPROVAL_FOLDERID);
    }
}