Example #1
0
        public ActionResult LoadAppyOnBehalf(DateTime?StartDate, DateTime?LeaveUpto)
        {
            ViewBag.PageTile = "Apply For Leave Others";
            var   request = new LeaveRequestModel();
            Int64 userId  = (Int64)TempData["ApplyForUserId"];

            request.UserId = userId;
            if (StartDate != null)
            {
                request.LeaveFrom = StartDate.Value;
            }
            else
            {
                request.NumberOfDays = 1;
                request.LeaveFrom    = System.DateTime.Now;
            }
            if (LeaveUpto != null)
            {
                request.LeaveUpto = LeaveUpto.Value;
            }
            else
            {
                request.LeaveUpto = System.DateTime.Now;
            }
            using (var Client = new LeaveClient())
            {
                var commonData = Client.ApplyLeaveCommonData(this.OfficeId, userId);
                request.lstLeaveTypes         = commonData.lstLeaveTypes;
                request.lstSummary            = commonData.lstSummary;
                request.WeekOffs              = commonData.WeekOffs;
                request.holidayDates          = commonData.holidayDates;
                request.TimebasedLeaveTypeIds = commonData.TimebasedLeaveTypeIds;
            }
            using (var Client = new EmployeeClient())
            {
                request.ReportingToName = Client.ReportingToName(userId);
            }

            request.ViewTitle      = "Apply Request For " + TempData["ApplyForName"].ToString();
            request.ApplyMode      = "Others";
            request.ApplyForUserId = userId;
            return(View("ApplyFor", request));
        }
Example #2
0
        public ActionResult Apply(DateTime?StartDate, DateTime?LeaveUpto)
        {
            ViewBag.PageTile = "Apply For Leave";

            var request = new LeaveRequestModel
            {
                UserId = this.UserId
            };

            if (StartDate != null)
            {
                request.LeaveFrom = StartDate.Value;
            }
            else
            {
                request.NumberOfDays = 1;
                request.LeaveFrom    = System.DateTime.Now;
            }

            if (LeaveUpto != null)
            {
                request.LeaveUpto = LeaveUpto.Value;
            }
            else
            {
                request.LeaveUpto = System.DateTime.Now;
            }

            using (var Client = new LeaveClient())
            {
                var commonData = Client.ApplyLeaveCommonData(this.OfficeId, this.UserId);
                request.lstLeaveTypes         = commonData.lstLeaveTypes;
                request.lstSummary            = commonData.lstSummary;
                request.WeekOffs              = commonData.WeekOffs;
                request.holidayDates          = commonData.holidayDates;
                request.TimebasedLeaveTypeIds = commonData.TimebasedLeaveTypeIds;
            }

            request.ReportingToName = this.ReportingToName;

            return(View(request));
        }
Example #3
0
        public ActionResult SaveLeaveRequest(LeaveRequestModel data)
        {
            bool  isValid = true;
            Int64 userId  = 0;

            if (ModelState.IsValid)
            {
                if (data.ApplyMode == "Others")
                {
                    if (this.Role == "HR" || this.Role == "Admin")
                    {
                    }
                    else
                    {
                        data.ErrorMesage = "You are not authorized to apply request on behalf of others.";
                        isValid          = false;
                    }
                }

                if (data.ApplyMode == "Others")
                {
                    userId = data.ApplyForUserId;
                }
                else
                {
                    userId = this.UserId;
                }

                if (data.LeaveFrom > data.LeaveUpto)
                {
                    data.ErrorMesage = "Please select correct From and To dates for the request.";
                    isValid          = false;
                }

                if (data.Reason != null)
                {
                    if (data.Reason.Trim() == string.Empty)
                    {
                        data.ErrorMesage = "Please provide the reason for this request.";
                        isValid          = false;
                    }
                }
                else
                {
                    data.ErrorMesage = "Please provide the reason for this request.";
                    isValid          = false;
                }

                //remove unnecessary data for half day leave
                //remove unnecessary data for permission
                //casual leave max dys get from DB

                if (data.IsTimeBased != "Time")
                {
                    if (isValid)
                    {
                        if (data.LeaveFrom.Year != data.LeaveUpto.Year)
                        {
                            data.ErrorMesage = "The leave request duration should be within the same year.";
                            isValid          = false;
                        }
                        if (data.NumberOfDays <= 0)
                        {
                            data.ErrorMesage = "Please select correct From and To dates for the request.";
                            isValid          = false;
                        }
                    }
                }
                else
                {
                    if (data.IsOverTime == "Yes")
                    {
                        data.LeaveFrom = data.PermissionDate;
                    }
                }
                if (data.LeaveFrom == data.LeaveUpto)
                {
                    if (data.LeaveFromTime == "F")
                    {
                        data.LeaveUptoTime = "F";
                    }
                    else if (data.LeaveFromTime == "S")
                    {
                        data.LeaveUptoTime = "S";
                    }
                }

                using (var client = new LeaveClient())
                {
                    data.UserId          = userId;
                    data.AppliedByUserId = this.UserId;
                    if (isValid)
                    {
                        string result = client.SaveLeaveRequest(data);
                        if (result == null || result == string.Empty)
                        {
                            data.ErrorMesage = "Unhandled exception occurred.";
                        }
                        else
                        {
                            if (result.IndexOf("$") > 0)
                            {
                                data.ErrorMesage = "Saved";

                                try
                                {
                                    EmailHelper emailHelper = new EmailHelper();
                                    //#if DEBUG
                                    emailHelper.SendRequestEmail(Convert.ToInt64(result.Substring(6)), "Pending");
                                    //#else
                                    //BackgroundJob.Enqueue(() => emailHelper.SendEmail(Convert.ToInt64(result.Substring(6)), "Pending"));
                                    //#endif
                                }
                                catch
                                {
                                    data.ErrorMesage = "EmailFailed";
                                }
                            }
                            else if (result == "Duplicate")
                            {
                                data.ErrorMesage = "There is a previously applied request falling within this date range.";
                            }
                            else if (result.Contains("LeaveExceeded"))
                            {
                                data.ErrorMesage = "You cannot apply for days more than the available leaves. Number of leaves available are " + result.Substring(14) + ".";
                            }
                            else if (result == "Leave balance profile not created")
                            {
                                data.ErrorMesage = "Leave balance has not yet been credited for you.";
                            }
                            else if (result == "HolidayFromDate")
                            {
                                data.ErrorMesage = "Leave from date is a holiday. Please select working day.";
                            }
                            else if (result == "HolidayToDate")
                            {
                                data.ErrorMesage = "Leave upto date is a holiday. Please select working day.";
                            }
                            else if (result == "PermissionProperDateRange")
                            {
                                data.ErrorMesage = "Please select correct date.";
                            }
                            else if (result == "PermissionProperTime")
                            {
                                data.ErrorMesage = "Please select the correct time duration.";
                            }
                            else if (result == "PermissionDurationTime")
                            {
                                data.ErrorMesage = "Total permission time exceeds the duration allowed per month.";
                            }
                            else if (result == "PermissionDateTobeSame")
                            {
                                data.ErrorMesage = "The From and To dates should be same for this type of request.";
                            }
                            else if (result.Contains("ExceedMaxPerRequest"))
                            {
                                data.ErrorMesage = "Maximum number of days allowed per request are " + result.Substring(19) + ".";
                            }
                            else if (result == "MinDaysForCL")
                            {
                                data.ErrorMesage = "Casual Leave has to be applied 3 days prior to availing.";
                            }
                            else if (result == "MinDaysForSL")
                            {
                                data.ErrorMesage = "Sick/Unplanned Leave cannot be applied for future dates.";
                            }
                            else if (result == "MinDaysForEL")
                            {
                                data.ErrorMesage = "Earned Leave has to be applied 14 days prior to availing.";
                            }
                            else if (result.Contains("BelowMinPerRequest"))
                            {
                                data.ErrorMesage = "Minimum number of days allowed per request are 3.";
                            }
                            else if (result == "CheckException")
                            {
                                data.ErrorMesage = "Combining leaves is an exception. Please avail leave combination exception";
                            }
                            else if (result == "UnCheckException")
                            {
                                data.ErrorMesage = "No combination of leaves found. Please uncheck avail leave combination exception";
                            }
                            else if (result == "CLExceptionNotAllowed")
                            {
                                data.ErrorMesage = "Casual leaves cannot be extended. Please apply Sick/Unplanned Leave or Leave Without Pay";
                            }
                            else if (result.Contains("MaxExceptionsAvailed:"))
                            {
                                data.ErrorMesage = "You have already availed " + result.Substring(21) + " leave exceptions. Please apply Leave Without Pay.";
                            }
                        }
                    }
                }
            }
            else
            {
                data.ErrorMesage = "There is invalid data in request.";
            }
            using (var Client = new LeaveClient())
            {
                var commonData = Client.ApplyLeaveCommonData(this.OfficeId, userId);
                data.lstLeaveTypes         = commonData.lstLeaveTypes;
                data.lstSummary            = commonData.lstSummary;
                data.WeekOffs              = commonData.WeekOffs;
                data.holidayDates          = commonData.holidayDates;
                data.TimebasedLeaveTypeIds = commonData.TimebasedLeaveTypeIds;
            }
            using (var Client = new EmployeeClient())
            {
                data.ReportingToName = Client.ReportingToName(data.UserId);
            }
            if (data.ApplyMode == "Others")
            {
                return(View("ApplyFor", data));
            }
            else
            {
                return(Json(data.ErrorMesage));
            }
        }