public IList <INoticeDTO> GetAllNotices() { IList <INoticeDTO> noticeDTOList = null; using (EmployeePortalEntities employeePortalEntities = new EmployeePortalEntities()) { try { var noticeEntityList = employeePortalEntities.Notices; if (noticeEntityList != null) { noticeDTOList = new List <INoticeDTO>(); foreach (var notice in noticeEntityList) { INoticeDTO noticeDTO = (INoticeDTO)DTOFactory.Instance.Create(DTOType.Notice); EntityConverter.FillDTOFromEntity(notice, noticeDTO); noticeDTOList.Add(noticeDTO); } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException(ex.Message, ex); } } return(noticeDTOList); }
public int InsertNotice(INoticeDTO noticeDTO) { int retVal = default(int); using (EmployeePortalEntities employeePortalEntities = new EmployeePortalEntities()) { try { Notice newNotice = new Notice(); //EntityConverter.FillEntityFromDTO(noticeDTO, newNotice); newNotice.Title = noticeDTO.Title; newNotice.Description = noticeDTO.Description; newNotice.StartDate = noticeDTO.StartDate; newNotice.ExpirationDate = noticeDTO.ExpirationDate; newNotice.PostedBy = noticeDTO.PostedById; Notice addedNotice = employeePortalEntities.Notices.Add(newNotice); employeePortalEntities.SaveChanges(); retVal = addedNotice.NoticeId; } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException(ex.Message, ex); } } return(retVal); }
public bool UpdateNotice(INoticeDTO noticeDTO) { bool retVal = false; using (EmployeePortalEntities employeePortalEntities = new EmployeePortalEntities()) { try { var noticeEntity = employeePortalEntities.Notices.FirstOrDefault(notice => notice.NoticeId == noticeDTO.NoticeId); if (noticeEntity != null) { noticeEntity.Title = noticeDTO.Title; noticeEntity.Description = noticeDTO.Description; noticeEntity.StartDate = noticeDTO.StartDate; noticeEntity.ExpirationDate = noticeDTO.ExpirationDate; employeePortalEntities.SaveChanges(); retVal = true; } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException(ex.Message, ex); } } return(retVal); }
/// <summary> /// Create a new entry in the notice table , if inserted successfully /// a.Yes – return the inserted NoticeDTO /// b.No – return null /// </summary> /// <param name="noticeDTO"></param> /// <returns></returns> public INoticeDTO CreateNotice(INoticeDTO noticeDTO) { INoticeDTO createNoticeRetval = null; try { using (EmployeePortal2017Entities portal = new EmployeePortal2017Entities()) { noticeDTO.IsActive = true; Notice notice = new Notice(); EntityConverter.FillEntityFromDTO(noticeDTO, notice); portal.Notices.Add(notice); if (portal.SaveChanges() > 0) { noticeDTO.NoticeId = notice.NoticeId; createNoticeRetval = noticeDTO; } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException(ex.Message); } return(createNoticeRetval); }
/// <summary> /// Get all the notices with IsActive set to true. /// </summary> /// <returns></returns> public IList <INoticeDTO> GetActiveNotices() { IList <INoticeDTO> noticeDTOList = null; try { using (EmployeePortal2017Entities portal = new EmployeePortal2017Entities()) { var noticeList = portal.Notices.Include("Employee").Where(n => n.IsActive).ToList(); if (noticeList.Count > 0) { noticeDTOList = new List <INoticeDTO>(); INoticeDTO noticeDTO = null; foreach (Notice notice in noticeList) { noticeDTO = (INoticeDTO)DTOFactory.Instance.Create(DTOType.NoticeDTO); noticeDTO.PostedByEmployee = (IEmployeeDTO)DTOFactory.Instance.Create(DTOType.EmployeeDTO); EntityConverter.FillDTOFromEntity(notice, noticeDTO); EntityConverter.FillDTOFromEntity(notice.Employee, noticeDTO.PostedByEmployee); noticeDTOList.Add(noticeDTO); } } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException(ex.Message); } return(noticeDTOList); }
/// <summary> /// Returns a specific notice using the given notice id /// </summary> /// <param name="noticeId"></param> /// <returns></returns> public INoticeDTO GetNotice(int noticeId) { INoticeDTO noticeDTO = null; using (EmployeePortal2017Entities portal = new EmployeePortal2017Entities()) { try { var notice = portal.Notices.Include("Employee").Where(n => n.NoticeId == noticeId) .SingleOrDefault(); if (notice != null) { noticeDTO = (INoticeDTO)DTOFactory.Instance.Create(DTOType.NoticeDTO); noticeDTO.PostedByEmployee = (IEmployeeDTO)DTOFactory.Instance.Create(DTOType.EmployeeDTO); EntityConverter.FillDTOFromEntity(notice, noticeDTO); EntityConverter.FillDTOFromEntity(notice.Employee, noticeDTO.PostedByEmployee); } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException(ex.Message); } } return(noticeDTO); }
/// <summary> /// Update the notice table accordingly, Is Updated successfully /// a.Yes – return the updated NoticeDTO /// b.No – return Null /// </summary> /// <param name="noticeDTO"></param> /// <returns></returns> public INoticeDTO UpdateNotice(INoticeDTO noticeDTO) { INoticeDTO retVal = null; try { using (EmployeePortal2017Entities portal = new EmployeePortal2017Entities()) { var notice = portal.Notices.Where(n => n.NoticeId == noticeDTO.NoticeId).SingleOrDefault <Notice>(); if (notice != null) { noticeDTO.IsActive = notice.IsActive; EntityConverter.FillEntityFromDTO(noticeDTO, notice); if (portal.SaveChanges() > 0) { retVal = noticeDTO; } } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException(ex.Message); } return(retVal); }
public OperationResult <INoticeDTO> GetNotice(int noticeId) { OperationResult <INoticeDTO> getNoticeReturnValue = null; try { INoticeDAC noticeDAC = (INoticeDAC)DACFactory.Instance.Create(DACType.NoticeManagerDAC); INoticeDTO noticeDTO = noticeDAC.GetNotice(noticeId); if (noticeDTO != null) { getNoticeReturnValue = OperationResult <INoticeDTO> .CreateSuccessResult(noticeDTO); } else { getNoticeReturnValue = OperationResult <INoticeDTO> .CreateFailureResult("Notice Id does not exist"); } } catch (DACException dacEx) { getNoticeReturnValue = OperationResult <INoticeDTO> .CreateErrorResult(dacEx.Message, dacEx.StackTrace); } catch (Exception ex) { ExceptionManager.HandleException(ex); getNoticeReturnValue = OperationResult <INoticeDTO> .CreateErrorResult(ex.Message, ex.StackTrace); } return(getNoticeReturnValue); }
public OperationResult <INoticeDTO> UpdateNotice(INoticeDTO noticeDTO) { OperationResult <INoticeDTO> updateNoticeReturnValue = null; try { INoticeDAC noticeDAC = (INoticeDAC)DACFactory.Instance.Create(DACType.NoticeManagerDAC); EmployeePortalValidationResult validationResult = Validator <NoticeValidator, INoticeDTO> .Validate(noticeDTO, ValidationConstants.Common); if (!validationResult.IsValid) { updateNoticeReturnValue = OperationResult <INoticeDTO> .CreateFailureResult(validationResult); } else { INoticeDTO returnedNoticeDTO = noticeDAC.UpdateNotice(noticeDTO); if (returnedNoticeDTO != null) { updateNoticeReturnValue = OperationResult <INoticeDTO> .CreateSuccessResult(returnedNoticeDTO, "Notice updated successfully"); } } } catch (DACException dacEx) { updateNoticeReturnValue = OperationResult <INoticeDTO> .CreateErrorResult(dacEx.Message, dacEx.StackTrace); } catch (Exception ex) { ExceptionManager.HandleException(ex); updateNoticeReturnValue = OperationResult <INoticeDTO> .CreateErrorResult(ex.Message, ex.StackTrace); } return(updateNoticeReturnValue); }
public ActionResult CreateNotice(NoticeModel notice) { ActionResult retVal = null; if (ModelState.IsValid) { notice.PostedBy = SessionStateManager <UserInfo> .Data.Employee.EmployeeId; INoticeDTO noticeDTO = (INoticeDTO)DTOFactory.Instance.Create(DTOType.NoticeDTO); DTOConverter.FillDTOFromViewModel(noticeDTO, notice); INoticeFacade noticeFacade = (INoticeFacade)FacadeFactory.Instance.Create(FacadeType.NoticeManagerFacade); OperationResult <INoticeDTO> result = noticeFacade.CreateNotice(noticeDTO); if (result.IsValid()) { retVal = new JsonResult() { Data = new { Message = "Notice created 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); //retVal = PartialView("~/Views/Shared/_CreateNotice.cshtml",notice); } else if (result.HasFailed()) { //retVal = RedirectToAction("GetActiveNotices", "Notice"); retVal = new JsonResult() { Data = new { Message = "Notice Creation 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 : "); } }
public INoticeDTO GetNotice(int noticeId) { INoticeDTO noticeDTO = null; using (EmployeePortalEntities employeePortalEntities = new EmployeePortalEntities()) { try { var noticeEntity = employeePortalEntities.Notices.FirstOrDefault(notice => notice.NoticeId == noticeId); if (noticeEntity != null) { noticeDTO = (INoticeDTO)DTOFactory.Instance.Create(DTOType.Notice); EntityConverter.FillDTOFromEntity(noticeEntity, noticeDTO); } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException(ex.Message, ex); } } return(noticeDTO); }
public OperationResult <INoticeDTO> UpdateNotice(INoticeDTO noticeDTO) { INoticeBDC noticeBDC = (INoticeBDC)BDCFactory.Instance.Create(BDCType.NoticeManagerBDC); return(noticeBDC.UpdateNotice(noticeDTO)); }