// The id parameter name should match the DataKeyNames value set on the control
 public void gvJobPostings_DeleteItem(Posting posting)
 {
     using (var context = new CareersContext())
     {
         context.Entry(posting).State = System.Data.Entity.EntityState.Deleted;
         context.SaveChanges();
     }
 }
        private void SendUnapprovedNotification(Posting posting)
        {
            if (ConfigurationManager.AppSettings["SendCareersNotifications"] != null && bool.Parse(ConfigurationManager.AppSettings["SendCareersNotifications"]))
            {
                try
                {
                    //todo set up mail correctly
                    MailMessage mailMessage = new MailMessage();
                    mailMessage.To.Add(ConfigurationManager.AppSettings["CareersToEmail"]);
                    mailMessage.From = new MailAddress(ConfigurationManager.AppSettings["CareersFromEmail"]);
                    mailMessage.Subject = "Job Posting " + posting.JobID + " Needs to be approved";
                    mailMessage.Body = "Job Posting " + posting.JobID + " Needs to be approved <br /><br /> " + HttpContext.Current.Request.Url.AbsoluteUri;
                    mailMessage.IsBodyHtml = true;

                    SmtpClient smtpClient = new SmtpClient(ConfigurationManager.AppSettings["CareersSmtpClient"]);
                    smtpClient.Send(mailMessage);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        public void fvJobPosting_UpdateItem(Posting posting)
        {
            if (((bool)(Session["ChangeToEditMode"] ?? false) || (bool)(Session["ChangeToViewMode"] ?? false)))
            {
                Session["Posting"] = posting;
            }
            else
            {
                UpdatePosting(posting);

            }
        }
        private void UpdatePosting(Posting posting)
        {
            using (var context = new CareersContext())
            {
                if (posting.JobID == 0 && !IsStaffUser && PostingCredits <= 0) Response.Redirect(Request.Url.AbsoluteUri);
                bool decrementJobCredits = false;
                var postDateString = string.Empty;
                DateTime postDate;
                var postDateTextbox = (TextBox)fvJobPosting.FindControl("txtPostDate");
                if (postDateTextbox.Text != null && DateTime.TryParse(postDateTextbox.Text, out postDate)) posting.PostDate = postDate;
                else posting.PostDate = null;
                if (posting.JobID == 0)
                {
                    context.Entry(posting).State = System.Data.Entity.EntityState.Added;
                    if (!IsStaffUser) decrementJobCredits = true;
                }
                else context.Entry(posting).State = System.Data.Entity.EntityState.Modified;
                if (posting.Approved == false) SendUnapprovedNotification(posting);
                context.SaveChanges();
                if (decrementJobCredits) PostingCredits = PostingCredits - 1;

            }
            Response.Redirect(Request.Url.AbsolutePath + "?PostingId=" + posting.JobID.ToString());
        }