Beispiel #1
0
 private static void FillDetailsOfLoggedInUser(IUserDTO loginResult, UserInfo userInfo)
 {
     FormsAuthentication.SetAuthCookie(loginResult.EmployeeDTO.Email, false);
     DTOConverter.FillViewModelFromDTO(userInfo, loginResult);
     userInfo.Employee = new EmployeeInfo();
     DTOConverter.FillViewModelFromDTO(userInfo.Employee, loginResult.EmployeeDTO);
 }
        public ActionResult GetCurrentNotices()
        {
            ActionResult  retVal       = null;
            INoticeFacade noticeFacade = (INoticeFacade)FacadeFactory.Instance.Create(FacadeType.NoticeManagerFacade);
            OperationResult <IList <INoticeDTO> > result = noticeFacade.GetCurrentNotices();

            IList <NoticeModel> noticeModelList = null;

            if (result.IsValid())
            {
                noticeModelList = new List <NoticeModel>();
                NoticeModel noticeModel = null;
                foreach (INoticeDTO noticeDTO in result.Data)
                {
                    noticeModel = new NoticeModel();
                    DTOConverter.FillViewModelFromDTO(noticeModel, noticeDTO);
                    noticeModel.NotifierEmployeeName = noticeDTO.PostedByEmployee.FirstName + " " + noticeDTO.PostedByEmployee.LastName;
                    noticeModelList.Add(noticeModel);
                }
                retVal = View("~/Views/Notice/GetNotices.cshtml", noticeModelList);
            }
            else if (result.HasFailed())
            {
                retVal = RedirectToAction("Index", "Notice");
            }
            else
            {
                retVal = View("~/Views/Shared/Error.cshtml");
            }
            return(retVal);
        }
        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);
        }
        public ActionResult NoticeDetails(int noticeId)
        {
            ActionResult  retVal                = null;
            INoticeFacade noticeFacade          = (INoticeFacade)FacadeFactory.Instance.Create(FacadeType.NoticeManagerFacade);
            OperationResult <INoticeDTO> result = noticeFacade.GetNotice(noticeId);

            if (result.IsValid())
            {
                NoticeModel notice = new NoticeModel();
                DTOConverter.FillViewModelFromDTO(notice, result.Data);
                notice.NotifierEmployeeName = result.Data.PostedByEmployee.FirstName + " " + result.Data.PostedByEmployee.LastName;
                retVal = PartialView("~/Views/Notice/_NoticeDetails.cshtml", notice);
            }
            else if (result.HasFailed())
            {
                retVal = RedirectToAction("GetActiveNotices", "Notice");
            }
            else
            {
                retVal = View("~/Views/Shared/Error.cshtml");
            }
            return(retVal);
        }
        public ActionResult EditNotice(int noticeId)
        {
            ActionResult  retVal                = null;
            INoticeFacade noticeFacade          = (INoticeFacade)FacadeFactory.Instance.Create(FacadeType.NoticeManagerFacade);
            OperationResult <INoticeDTO> result = noticeFacade.GetNotice(noticeId);

            if (result.IsValid())
            {
                NoticeModel notice = new NoticeModel();
                DTOConverter.FillViewModelFromDTO(notice, result.Data);
                ViewBag.Create = false;
                retVal         = PartialView("~/Views/Notice/_EditNotice.cshtml", notice);
            }
            else if (result.HasFailed())
            {
                retVal = RedirectToAction("GetActiveNotices", "Notice");
            }
            else
            {
                retVal = View("~/Views/Shared/Error.cshtml");
            }
            return(retVal);
        }
Beispiel #6
0
        public ActionResult EditProfile(User user)
        {
            ActionResult retVal = null;

            if (ModelState.IsValid)
            {
                bool isPasswordChanged = false;
                user.EmployeeId               = SessionStateManager <UserInfo> .Data.EmployeeId;
                user.IsAdmin                  = SessionStateManager <UserInfo> .Data.IsAdmin;
                user.Employee.EmployeeId      = SessionStateManager <UserInfo> .Data.Employee.EmployeeId;
                user.Employee.TerminationDate = SessionStateManager <UserInfo> .Data.Employee.TerminationDate;
                if (user.OldPassword != null)
                {
                    if ((user.OldPassword.Equals(SessionStateManager <UserInfo> .Data.Password)) && (user.NewPassword != null))
                    {
                        user.Password     = user.NewPassword;
                        isPasswordChanged = true;
                    }
                }
                else
                {
                    user.Password = SessionStateManager <UserInfo> .Data.Password;
                }

                IUserDTO userDTO = (IUserDTO)DTOFactory.Instance.Create(DTOType.UserDTO);
                DTOConverter.FillDTOFromViewModel(userDTO, user);
                userDTO.EmployeeDTO = (IEmployeeDTO)DTOFactory.Instance.Create(DTOType.EmployeeDTO);
                DTOConverter.FillDTOFromViewModel(userDTO.EmployeeDTO, user.Employee);

                IUserFacade userFacade            = (IUserFacade)FacadeFactory.Instance.Create(FacadeType.UserManagerFacade);
                OperationResult <IUserDTO> result = userFacade.UpdateProfile(userDTO);
                if (result.IsValid())
                {
                    if (isPasswordChanged)
                    {
                        retVal = RedirectToAction("Logout");
                    }
                    else
                    {
                        var userInfo = SessionStateManager <UserInfo> .Data;
                        FillDetailsOfLoggedInUser(result.Data, userInfo);
                        retVal = RedirectToAction("Index", "Home");
                    }
                }
                else if (result.HasValidationFailed() && (result.ValidationResult != null))
                {
                    foreach (EmployeePortalValidationFailure error in result.ValidationResult.Errors)
                    {
                        ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                    }
                    retVal = View(user);
                }
                else if (result.HasFailed())
                {
                }
                else
                {
                    retVal = View("~/Views/Shared/Error.cshtml");
                }
            }
            return(retVal);
        }