Esempio n. 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (this.IsValid)
            {
                if (CalendarPopup1.SelectedDate.GetValueOrDefault() > CalendarPopup2.SelectedDate.GetValueOrDefault())
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "date", "alert('End Date cannot be earlier than Start Date');", true);
                    return;
                }

                try
                {
                    using (var ctx = new VIPDCEntities())
                    {
                        Alert entity = RowID == 0 ? new Alert() : ctx.Alerts.Single(row => row.ID == RowID);
                        entity.Subject     = txtSubject.Text;
                        entity.Description = txtDescription.Text;
                        entity.StartDate   = CalendarPopup1.SelectedDate.GetValueOrDefault();
                        entity.EndDate     = chkInfinite.Checked ? null : CalendarPopup2.SelectedDate;
                        entity.Active      = chkActive.Checked;
                        entity.EmployeeID  = Convert.ToInt32(ddlPIC.SelectedValue);
                        //entity.BackColor = RadColorPicker1.SelectedColor.ToArgb();
                        if (RowID == 0)
                        {
                            entity.CreatedWhen = DateTime.Now;
                            entity.CreatedWho  = User.Identity.Name;
                            ctx.Alerts.Add(entity);
                        }
                        entity.ChangedWhen = DateTime.Now;
                        entity.ChangedWho  = User.Identity.Name;
                        ctx.SaveChanges();
                    }

                    WebFormHelper.SetLabelTextWithCssClass(lblStatus, "Data has been saved.", LabelStyleNames.InfoMessage);
                }
                catch (Exception ex)
                {
                    WebFormHelper.SetLabelTextWithCssClass(lblStatus, ex.Message, LabelStyleNames.ErrorMessage);
                    //ApplicationLogger.Write(ex);
                }
                finally
                {
                    Refresh();
                }
            }
        }
Esempio n. 2
0
        protected void lnbDelete_Click(object sender, EventArgs e)
        {
            int[] arrayOfID = RadHelper.GetRowIdForDeletion(RadGrid1);

            try
            {
                using (var ctx = new VIPDCEntities())
                {
                    ctx.Alerts.Where(row => arrayOfID.Contains(row.ID)).ForEach(
                        alert => ctx.Alerts.Remove(alert));
                    ctx.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                WebFormHelper.SetLabelTextWithCssClass(lblStatus, ex.Message, LabelStyleNames.ErrorMessage);
                //ApplicationLogger.Write(ex);
            }
            Refresh();
        }