public IList <INoticesDTO> GetActiveNotices() { List <INoticesDTO> activeNotices = new List <INoticesDTO>(); try { using (EmployeePortalEntities context = new EmployeePortalEntities()) { //check whether we need to check here whether notice is active or not foreach (var notice in context.Notices.Where(item => item.IsActive == true)) { INoticesDTO noticeDTO = (INoticesDTO)DTOFactory.Instance.Create(DTOType.NoticesDTO); EntityConverter.FillDTOFromEntity(notice, noticeDTO); activeNotices.Add(noticeDTO); context.SaveChanges(); } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException(ex.Message); } return(activeNotices); }
public OperationResult <INoticesDTO> UpdateNotice(INoticesDTO noticeDTO) { OperationResult <INoticesDTO> updateNoticeReturnValue = null; try { INoticesDAC noticeDAC = (INoticesDAC)DACFactory.Instance.Create(DACType.NoticesDAC); INoticesDTO returnedNoticeDTO = noticeDAC.UpdateNotice(noticeDTO); if (returnedNoticeDTO != null) { updateNoticeReturnValue = OperationResult <INoticesDTO> .CreateSuccessResult(returnedNoticeDTO, "Notice created successfully"); } else { updateNoticeReturnValue = OperationResult <INoticesDTO> .CreateFailureResult("Insertion failed!"); } } catch (DACException dacEx) { updateNoticeReturnValue = OperationResult <INoticesDTO> .CreateErrorResult(dacEx.Message, dacEx.StackTrace); } catch (Exception ex) { ExceptionManager.HandleException(ex); updateNoticeReturnValue = OperationResult <INoticesDTO> .CreateErrorResult(ex.Message, ex.StackTrace); } return(updateNoticeReturnValue); }
//public OperationResult<INoticesDTO> SampleMethod(INoticesDTO noticesDTO) //{ // OperationResult<INoticesDTO> retVal = null; // INoticesDAC noticesDAC = (INoticesDAC)DACFactory.Instance.Create(DACType.NoticesDAC); // noticesDTO = noticesDAC.SampleMethod(noticesDTO); // retVal = OperationResult<INoticesDTO>.CreateSuccessResult(noticesDTO); // return retVal; //} public OperationResult <INoticesDTO> CreateNotice(INoticesDTO noticesDTO) { OperationResult <INoticesDTO> createNoticeReturnValue = null; try { EmployeePortalValidationResult validationResult = Validator <NoticeValidator, INoticesDTO> .Validate(noticesDTO, ValidationConstants.NoticeMessages.TitleMandatory); if (!validationResult.IsValid) { createNoticeReturnValue = OperationResult <INoticesDTO> .CreateFailureResult(validationResult); } else { INoticesDAC noticeDAC = (INoticesDAC)DACFactory.Instance.Create(DACType.NoticesDAC); INoticesDTO returnedNoticeDTO = noticeDAC.CreateNotice(noticesDTO); if (returnedNoticeDTO != null) { createNoticeReturnValue = OperationResult <INoticesDTO> .CreateSuccessResult(returnedNoticeDTO, "Notice created successfully"); } else { createNoticeReturnValue = OperationResult <INoticesDTO> .CreateFailureResult("Insertion failed!"); } } } catch (DACException dacEx) { createNoticeReturnValue = OperationResult <INoticesDTO> .CreateErrorResult(dacEx.Message, dacEx.StackTrace); } catch (Exception ex) { ExceptionManager.HandleException(ex); createNoticeReturnValue = OperationResult <INoticesDTO> .CreateErrorResult(ex.Message, ex.StackTrace); } return(createNoticeReturnValue); }
public INoticesDTO UpdateNotice(INoticesDTO noticesDTO) { INoticesDTO retVal = null; try { using (EmployeePortalEntities context = new EmployeePortalEntities()) { var updateNotice = context.Notices.First(item => noticesDTO.NoticeId == item.NoticeId); if (updateNotice != null) { EntityConverter.FillEntityFromDTO(noticesDTO, updateNotice); context.SaveChanges(); retVal = noticesDTO; } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException(ex.Message); } return(retVal); }
public IList <INoticesDTO> GetCurrentNotices() { List <INoticesDTO> currentNotices = new List <INoticesDTO>(); try { using (EmployeePortalEntities context = new EmployeePortalEntities()) { foreach (var notice in context.Notices.Where(i => ((i.StartDate <= DateTime.Now) && (i.ExpirationDate >= DateTime.Now)) && i.IsActive == true)) { INoticesDTO noticeDTO = (INoticesDTO)DTOFactory.Instance.Create(DTOType.NoticesDTO); EntityConverter.FillDTOFromEntity(notice, noticeDTO); currentNotices.Add(noticeDTO); context.SaveChanges(); } } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException(ex.Message); } return(currentNotices); }
public INoticesDTO CreateNotice(INoticesDTO noticesDTO) { INoticesDTO createNoticeRetval = null; try { using (EmployeePortalEntities context = new EmployeePortalEntities()) { noticesDTO.IsActive = true; Notice notice = new Notice(); EntityConverter.FillEntityFromDTO(noticesDTO, notice); context.Notices.Add(notice); context.SaveChanges(); notice.NoticeId = noticesDTO.NoticeId; createNoticeRetval = noticesDTO; } } catch (Exception ex) { ExceptionManager.HandleException(ex); throw new DACException(ex.Message); } return(createNoticeRetval); }
public OperationResult <INoticesDTO> UpdateNotice(INoticesDTO noticesDTO) { INoticesBDC noticeBDC = (INoticesBDC)BDCFactory.Instance.Create(BDCType.NoticesBDC); return(noticeBDC.UpdateNotice(noticesDTO)); }