public IActionResult Edit(EditNoticeViewModel model) { if (ModelState.IsValid) { Notice notice = new Notice(); notice.Title = model.Title; notice.Content = model.Content; notice.No = model.No; if (_noticeBll.UpdateNotice(notice)) { return(Redirect("Index")); } } return(View()); }
public IActionResult Edit(EditNoticeViewModel editNotice) { if (ModelState.IsValid) { var notice = _noticeQueries.GetNoticeByNoticeId(editNotice.NoticeId); if (!notice.NoticeStart.Equals(Convert.ToDateTime(editNotice.NoticeStart)) || !notice.NoticeEnd.Equals(Convert.ToDateTime(editNotice.NoticeEnd))) { if (_noticeQueries.ShowNotice(editNotice.NoticeStart, editNotice.NoticeEnd)) { ModelState.AddModelError("", "Notice Already Exits Between Selected Dates"); return(View(editNotice)); } else { notice.NoticeStart = Convert.ToDateTime(editNotice.NoticeStart); notice.NoticeEnd = Convert.ToDateTime(editNotice.NoticeEnd); notice.NoticeTitle = editNotice.NoticeTitle; notice.Status = editNotice.Status; notice.ModifiedOn = DateTime.Now; notice.ModifiedBy = Convert.ToInt32(HttpContext.Session.GetString(AllSessionKeys.UserId)); _unitOfWorkEntityFramework.NoticeCommand.UpdateNotice(notice); var noticedetails = _noticeQueries.GetNoticeDetailsByNoticeId(editNotice.NoticeId); noticedetails.Notice = notice; noticedetails.NoticeBody = HttpUtility.HtmlDecode(editNotice.NoticeBody); noticedetails.NoticeId = editNotice.NoticeId; _unitOfWorkEntityFramework.NoticeDetailsCommand.UpdateNoticeDetails(noticedetails); var result = _unitOfWorkEntityFramework.Commit(); if (result) { _notificationService.SuccessNotification("Message", "The Notice was updated Successfully!"); } return(RedirectToAction("Index")); } } else { notice.NoticeStart = Convert.ToDateTime(editNotice.NoticeStart); notice.NoticeEnd = Convert.ToDateTime(editNotice.NoticeEnd); notice.NoticeTitle = editNotice.NoticeTitle; notice.Status = editNotice.Status; notice.ModifiedOn = DateTime.Now; notice.ModifiedBy = Convert.ToInt32(HttpContext.Session.GetString(AllSessionKeys.UserId)); _unitOfWorkEntityFramework.NoticeCommand.UpdateNotice(notice); var noticedetails = _noticeQueries.GetNoticeDetailsByNoticeId(editNotice.NoticeId); noticedetails.Notice = notice; noticedetails.NoticeBody = HttpUtility.HtmlDecode(editNotice.NoticeBody); noticedetails.NoticeId = editNotice.NoticeId; _unitOfWorkEntityFramework.NoticeDetailsCommand.UpdateNoticeDetails(noticedetails); var result = _unitOfWorkEntityFramework.Commit(); if (result) { _notificationService.SuccessNotification("Message", "The Notice was updated Successfully!"); return(RedirectToAction("Index")); } } } return(View(editNotice)); }