Exemplo n.º 1
0
        public ActionResult ApplyLeave()
        {
            ViewBag.LeaveType     = LeaveServices.GetAllLeaveType();
            ViewBag.LeaveDuration = LeaveServices.GetAllLeaveDuration();
            LeaveModel model = new LeaveModel();

            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> ApplyLeave(LeaveModel model)
        {
            ViewBag.LeaveType     = LeaveServices.GetAllLeaveType();
            ViewBag.LeaveDuration = LeaveServices.GetAllLeaveDuration();
            if (ModelState.IsValid)
            {
                DateTime           StartDate;
                DateTime           EndDate;
                LeaveRequestEntity ob = new LeaveRequestEntity();
                if (model.StartTime == null)
                {
                    TempData[HRMWeb.Helpers.AlertStyles.Warning] = "Please Input Start Date";
                    return(View(model));
                }
                if (model.EndTime == null)
                {
                    TempData[HRMWeb.Helpers.AlertStyles.Warning] = "Please Input End Date";
                    return(View(model));
                }

                StartDate = model.StartTime == null ? DateTime.Now.Date : (DateTime)model.StartTime;
                EndDate   = model.EndTime == null ? DateTime.Now.Date : (DateTime)model.EndTime;

                if (StartDate > EndDate)
                {
                    TempData[HRMWeb.Helpers.AlertStyles.Warning] = "Start Date can not exceed End Date";
                    return(View(model));
                }
                ob.RequestId       = 0;
                ob.UserId          = HRMHelper.CurrentUser.UserId;
                ob.LeaveStatusId   = (int)LeaveServices.Leave_status_Type.PendingApproval;
                ob.LeaveTypeId     = model.LeaveTypeId;
                ob.LeaveDurationId = model.LeaveDurationId == 0 ? (int)LeaveServices.Leave_Duration.FullDay : model.LeaveDurationId;
                ob.StartTime       = StartDate;
                ob.EndTime         = EndDate;
                ob.Description     = model.Description;
                ob.UpdatedBy       = HRMHelper.CurrentUser.UserId;
                int x = LeaveServices.InsertUpdateLeave(ob);
                if (x > 0)
                {
                    ob.RequestId = x;
                    TempData[HRMWeb.Helpers.AlertStyles.Success] = "Leave Applied Successfully";
                    string MailMessage = "You applied for leave from " + ob.StartTime.ToString("MM/dd/yy") + " to " + ob.EndTime.ToString("MM/dd/yy");
                    string Heading     = "Leave Applied";
                    try
                    {
                        UserEntity manager = UserServices.GetUserByID(HRMHelper.CurrentUser.ManagerId);
                        string     CCMail  = manager.Email + "," + AppSettings.HRMail;
                        ArrayList  Urltext = new ArrayList();
                        ArrayList  Urls    = new ArrayList();
                        Urltext.Add("Click Here to check status");
                        Urls.Add(AppSettings.SiteURL + Url.Action("LeaveRecords", "Leave"));
                        await MailUtil.MailSend(Heading, HRMHelper.CurrentUser.Name, MailMessage, Urltext, Urls, HRMHelper.CurrentUser.Email, CCMail, Heading);
                    }
                    catch
                    { }
                }
                else
                {
                    TempData[HRMWeb.Helpers.AlertStyles.Danger] = "Leave Apply Fails";
                    return(View(model));
                }
            }
            model = new LeaveModel();
            return(View(model));
        }