protected void btnSave_Click(object sender, EventArgs e)
        {
            var cult = new System.Globalization.CultureInfo("pt-BR");

            long periodId = 0;
            phMessageError.Visible = false;
            phMessageSuccess.Visible = false;
            lblMessageError.Text = String.Empty;
            lblMessageSuccess.Text = String.Empty;

            Lib.Entities.Period p = new Lib.Entities.Period();
            p.ConvocationInitialDate = DateTime.Parse(txtConvocationInitialDate.Text, cult);
            p.ConvocationFinalDate = DateTime.Parse(txtConvocationFinalDate.Text, cult);
            p.FinalDate = DateTime.Parse(txtFinalDate.Text, cult);
            p.InitialDate = DateTime.Parse(txtInitialDate.Text, cult);
            p.Name = txtName.Text;
            p.Open = chkAberto.Checked;

            if (!String.IsNullOrEmpty(hdnPeriodId.Value))
            {
                periodId = Convert.ToInt64(Commons.SecurityUtils.descriptografar(hdnPeriodId.Value));

                p.Id = periodId;
            }

            using (Lib.Repositories.PeriodRepository repository = new Lib.Repositories.PeriodRepository(this.ActiveUser))
            {
                repository.save(p);

                if (repository.HasErrors)
                {
                    phMessageError.Visible = true;
                    lblMessageError.Text = String.Join(",", repository.Errors);
                }
                else
                {
                    phMessageSuccess.Visible = true;
                    if (periodId == 0)
                    {

                        lblMessageSuccess.Text = String.Format("Período '{0}' foi criado com sucesso!", txtName.Text);
                    }
                    else
                    {
                        lblMessageSuccess.Text = String.Format("Período '{0}' foi atualizado com sucesso!", txtName.Text);
                    }

                    Response.Redirect("~/Period/List.aspx");
                }
            }
        }
Ejemplo n.º 2
0
        public override void ProcessRequest(HttpContext context)
        {
            try
            {
                var periodIdString = context.Request.Form["Id"];
                long periodId = 0;
                long.TryParse(Commons.SecurityUtils.descriptografar(periodIdString), out periodId);

                if (periodId > 0)
                {
                    using (Lib.Repositories.PeriodRepository repository = new Lib.Repositories.PeriodRepository(this.ActiveUser))
                    {
                        var period = repository.getInstanceById(periodId);

                        if (period != null)
                        {
                            period.Published = true;
                            period.Open = false;

                            repository.save(period);
                        }
                        else
                        {
                            throw new Exception(Resources.Message.period_not_found);
                        }
                    }
                }
                else
                {
                    throw new Exception(Resources.Message.period_id_not_found);
                }

                context.Response.ContentType = "text/plain";
                context.Response.Write("Ok");
            }
            catch (Exception ex)
            {
                Lib.Log.ErrorLog.saveError("Web.Handler.ResponseForm.Action.ProcessRequest", ex);
                context.Response.StatusCode = 500;
                context.Response.Write(Resources.Message.couldnt_process_request);
            }
        }