public ActionResult EditNotice(NoticeModel notice) { ActionResult retVal = null; if (ModelState.IsValid) { INoticeDTO noticeDTO = (INoticeDTO)DTOFactory.Instance.Create(DTOType.NoticeDTO); DTOConverter.FillDTOFromViewModel(noticeDTO, notice); INoticeFacade noticeFacade = (INoticeFacade)FacadeFactory.Instance.Create(FacadeType.NoticeManagerFacade); OperationResult <INoticeDTO> result = noticeFacade.UpdateNotice(noticeDTO); if (result.IsValid()) { retVal = new JsonResult() { Data = new { Message = "Notice Updated Successfully", Success = true, RedirectUrl = Url.Action("GetActiveNotices", "Notice") }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } else if (result.HasValidationFailed() && (result.ValidationResult != null)) { foreach (EmployeePortalValidationFailure error in result.ValidationResult.Errors) { ModelState.AddModelError(error.PropertyName, error.ErrorMessage); } retVal = PartialView("~/Views/Notice/_EditNotice.cshtml", notice); } else if (result.HasFailed()) { retVal = new JsonResult() { Data = new { Message = "Notice Updation failed", Success = false, RedirectUrl = Url.Action("GetActiceNotices") }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } else { retVal = View("~/Views/Shared/Error.cshtml"); } } return(retVal); }
static void UpdateNotice() { INoticeDTO noticeDTO = (INoticeDTO)DTOFactory.Instance.Create(DTOType.NoticeDTO); int noticeId; System.Console.WriteLine("Notice Id : "); int.TryParse(System.Console.ReadLine(), out noticeId); noticeDTO.NoticeId = noticeId; System.Console.WriteLine("Title : "); noticeDTO.Title = System.Console.ReadLine(); System.Console.WriteLine("Description : "); noticeDTO.Description = System.Console.ReadLine(); System.Console.WriteLine("Posted By : "); int postedBy; int.TryParse(System.Console.ReadLine(), out postedBy); noticeDTO.PostedBy = postedBy; System.Console.WriteLine("Start Date : "); DateTime startDate; DateTime.TryParse(System.Console.ReadLine(), out startDate); noticeDTO.StartDate = startDate; System.Console.WriteLine("Expiration Date : "); DateTime expirationDate; DateTime.TryParse(System.Console.ReadLine(), out expirationDate); noticeDTO.ExpirationDate = expirationDate; INoticeFacade noticeFacade = (INoticeFacade)FacadeFactory.Instance.Create(FacadeType.NoticeManagerFacade); OperationResult <INoticeDTO> updateNoticesRetValue = noticeFacade.UpdateNotice(noticeDTO); if (updateNoticesRetValue.IsValid()) { System.Console.WriteLine("Notice updated!! Id : "); } }