Exemple #1
0
        public ActionResult Delete(string id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                using (VC_LMSEntities d = new VC_LMSEntities())
                {
                    var row = d.UsersTables.Where(x => x.EMPLOYEE_ID == id && x.ROLES == "Admin").FirstOrDefault();
                    if (row != null)
                    {
                        ViewBag.Message = "Cannot delete Admin";
                        return(View());
                    }
                    foreach (var item in d.Leaves)
                    {
                        if (item.Employee_Id == id)
                        {
                            d.Leaves.Remove(item);
                        }
                    }
                    UsersTable usertable = d.UsersTables.Where(x => x.EMPLOYEE_ID == id).FirstOrDefault();
                    d.UsersTables.Remove(usertable);
                    d.SaveChanges();
                }

                return(RedirectToAction("view"));
            }
            catch
            {
                return(View());
            }
        }
Exemple #2
0
        public ActionResult Edit(string id, LeaveManagementSystemValueCreed.Models.UsersTable user)
        {
            try
            {
                VC_LMSEntities    d = new VC_LMSEntities();
                List <RolesTable> r = new List <RolesTable>();
                foreach (var item in d.RolesTables)
                {
                    if (item.NAME != "Admin")
                    {
                        r.Add(item);
                    }
                }


                //ViewBag.Managers = new SelectList(d.managers, "manager_emp_id", "name");
                ViewBag.Departments = new SelectList(d.department_tbl, "DEPARTMENT", "DEPARTMENT");
                ViewBag.Roles       = new SelectList(r, "NAME", "NAME");
                if (user.Emp_end_date < user.Emp_start_date)
                {
                    ViewBag.Message = "Date of Joining Can't be Before Date of Leaving";
                    return(View());
                }
                // TODO: Add update logic here
                using (VC_LMSEntities db = new VC_LMSEntities())
                {
                    //var row = db.managers.Where(x => x.manager_emp_id == manger_id).FirstOrDefault();
                    //if (row != null)
                    //{
                    //    user.manager_name = row.name;
                    //}
                    //else
                    //{
                    //    ViewBag.Message = "No Such Manager Exists,Please give correct input or Create a manager";
                    //    return View();
                    //}


                    db.Entry(user).State = System.Data.Entity.EntityState.Modified;

                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Exemple #3
0
        public ActionResult Editmyleave(int id, LeaveManagementSystemValueCreed.Models.Leave leave)
        {
            try
            {
                using (VC_LMSEntities db = new VC_LMSEntities())
                {
                    db.Entry(leave).State = System.Data.Entity.EntityState.Modified;

                    db.SaveChanges();
                }
                // TODO: Add update logic here

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                string s = ex.Message;
                return(View());
            }
        }
Exemple #4
0
        public ActionResult ApplyLeave(LeaveManagementSystemValueCreed.Models.Leave leave)
        {
            //    leave.Start_Date = TimeZoneInfo.ConvertTimeToUtc(leave.Start_Date);
            //    leave.End_Date = TimeZoneInfo.ConvertTimeToUtc(leave.End_Date);
            var months = leave.Start_Date.Subtract(DateTime.Now);

            if (months.Days > 180)
            {
                ViewBag.Message = "Cannot Apply For more than 6 month in Advance";
                return(View());
            }
            VC_LMSEntities r         = new VC_LMSEntities();
            var            user_info = r.UsersTables.Where(w => w.EMPLOYEE_ID == leave.Employee_Id).FirstOrDefault();

            var indian_zone = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");

            if (DateTime.Now.Date.Kind == DateTimeKind.Utc)
            {
                if (leave.Start_Date.Subtract(TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.Date, indian_zone)).Days > 360)
                {
                    ViewBag.Message = "Cannot Apply for such date,as it is too Far";
                    return(View());
                }
            }
            else
            {
                if (leave.Start_Date.Subtract(DateTime.Now.Date).Days > 360)
                {
                    ViewBag.Message = "Cannot Apply for such date,as it is too Far";
                    return(View());
                }
            }
            bool   status  = false;
            string message = "";

            if (DateTime.Now.Date.Kind != DateTimeKind.Utc)
            {
                var datediff = DateTime.Now.Date.Subtract(leave.End_Date.Date);
                if (datediff.TotalDays > 0)
                {
                    ViewBag.Message = "Cannot Apply Leave  if End Date is in the Past";
                    ViewBag.Status  = false;
                    return(View());
                }
            }
            else if (DateTime.Now.Date.Kind == DateTimeKind.Utc)
            {
                var datediff = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.Date, indian_zone).Subtract(leave.End_Date);
                if (datediff.TotalDays > 0)
                {
                    ViewBag.Message = "Cannot Apply Leave  if End Date is in the Past";
                    ViewBag.Status  = false;
                    return(View());
                }
            }
            if (leave.End_Date > leave.Start_Date)
            {
                int            c  = 0;
                VC_LMSEntities dd = new VC_LMSEntities();
                foreach (var item in dd.Leaves)
                {
                    if ((Session["userID"].ToString()) == item.Employee_Id)
                    {
                        if ((item.Start_Date < leave.Start_Date) && (leave.End_Date < item.End_Date) && (item.Status != "Cancelled"))
                        {
                            ViewBag.Message = "Leave range falling under Another Leave Range ";
                            ViewBag.Status  = false;
                            ModelState.Clear();
                            return(View());
                        }
                        else if ((item.Start_Date < leave.Start_Date) && (leave.End_Date < item.End_Date) && (item.Status != "Cancelled"))
                        {
                            ViewBag.Message = "Leave date conflict,Please Apply after previous leave Ends ";
                            ViewBag.Status  = false;
                            ModelState.Clear();
                            return(View());
                        }
                        else if ((item.Start_Date < leave.Start_Date) && (leave.Start_Date < item.End_Date) && (item.Status != "Cancelled"))
                        {
                            ViewBag.Message = "Leave date conflict,Please Apply after previous leave Ends,or Edit ";
                            ViewBag.Status  = false;
                            ModelState.Clear();
                            return(View());
                        }

                        if ((leave.Start_Date == item.Start_Date || leave.End_Date == item.End_Date) && item.Status != "Cancelled")
                        {
                            ViewBag.Message = "Matching Date For Already Applied Leave Found,Please Cancel that Leave ";
                            ViewBag.Status  = false;
                            ModelState.Clear();
                            return(View());
                        }
                    }
                    if (item.Employee_Id == (Session["userID"].ToString()) && (item.Status == "Pending on Manager" || item.Status == "Approved By Manager" || item.Status == "Pending on Approvers" || item.Status == "Approved By Approvers"))
                    {
                        c += item.Number_of_Days;
                    }
                }
                var x       = (Session["userID"].ToString());
                var account = dd.UsersTables.Where(a => a.EMPLOYEE_ID == x).FirstOrDefault();

                if (account.leaves_alloted == 0)
                {
                    message = "Sorry Your Leave Balance is Zero and you cannot apply";
                    //return RedirectToAction("ApplyLeave");
                    status = false;
                }
                else
                {
                    int e              = 0;
                    var number_of_day  = leave.End_Date.Date.Subtract(leave.Start_Date.Date);
                    int number_of_days = 0;
                    number_of_days = number_of_day.Days + 1;
                    int             d = 0;
                    VC_LMSEntities4 p = new VC_LMSEntities4();
                    for (DateTime i = leave.Start_Date; i <= leave.End_Date; i = i.AddDays(1))
                    {
                        if (i.DayOfWeek == DayOfWeek.Saturday || i.DayOfWeek == DayOfWeek.Sunday)
                        {
                            e = e + 1;
                        }

                        foreach (var item in p.holidays)
                        {
                            if (item.Holiday_date == i)
                            {
                                e++;
                            }
                        }
                    }

                    number_of_days = number_of_days - e;

                    if ((c + number_of_days > account.leaves_alloted))
                    {
                        message         = "Already Applied or Approved leaves Exceeds Your Leave Balance";
                        status          = false;
                        ViewBag.Message = message;
                        ViewBag.Status  = status;
                    }
                    else if (number_of_days <= account.leaves_alloted)
                    {
                        try
                        {
                            leave.Start_Date = leave.Start_Date.Date;
                            leave.End_Date   = leave.End_Date.Date;


                            if (DateTime.Now.Date.Kind == DateTimeKind.Utc)
                            {
                                leave.Leave_apply_date = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.Date, indian_zone);
                            }
                            else if (DateTime.Now.Date.Kind != DateTimeKind.Utc)
                            {
                                leave.Leave_apply_date = DateTime.Now.Date;
                            }
                            VC_LMSEntities vc = new VC_LMSEntities();
                            int            k  = 0;
                            foreach (var item in vc.approvers)
                            {
                                if (item.Emplyoee_id == (Session["userID"].ToString()))
                                {
                                    k++;
                                }
                            }
                            if (k > 0)
                            {
                                leave.Status = "Pending on Approvers";
                            }
                            else if (k == 0)
                            {
                                leave.Status = "Pending on HR";
                            }
                            leave.Number_of_Days = number_of_days;
                            leave.Employe_name   = Session["userName"].ToString();
                            leave.Employee_Id    = (Session["userID"].ToString());
                            using (VC_LMSEntities f = new VC_LMSEntities())
                            {
                                var    row          = f.UsersTables.Where(m => m.ROLES == "HR").FirstOrDefault();
                                string EmailID      = row.EMAIL;
                                string employeename = leave.Employe_name;
                                int    days_Leave   = leave.Number_of_Days;
                                string hrname       = row.FIRST_NAME;
                                SendverificationLinkEmail(EmailID, employeename, days_Leave, hrname, leave.LeaveType);
                                var emp_id    = Session["userID"].ToString();
                                var apporvers = f.approvers.Where(y => y.Emplyoee_id == emp_id).FirstOrDefault();
                                if (apporvers != null)
                                {
                                    foreach (var item in f.approvers)
                                    {
                                        if (item.Emplyoee_id == emp_id)
                                        {
                                            var approvr      = f.UsersTables.Where(q => q.EMPLOYEE_ID == item.approver_id).FirstOrDefault();
                                            var approvername = approvr.FIRST_NAME;
                                            SendverificationLinkEmail(approvr.EMAIL, employeename, days_Leave, approvername, leave.LeaveType);
                                        }
                                    }
                                }
                                //var userinfo = f.UsersTables.Where(s => s.EMPLOYEE_ID == leave.Employee_Id).FirstOrDefault();
                                //var row2 = f.UsersTables.Where(m => m.EMPLOYEE_ID == userinfo.manager_id).FirstOrDefault();
                                //EmailID = row2.EMAIL;
                                //SendverificationLinkEmail(EmailID, employeename);


                                f.Leaves.Add(leave);
                                f.SaveChanges();
                                ModelState.Clear();
                                message        = "Successfully Applied";
                                ViewBag.Status = status;
                            }
                        }
                        catch (Exception ex)
                        {
                            ViewBag.Message = "Exclude Special Characters from Reason";
                            return(View());
                        }
                    }
                    else if (number_of_days < account.leaves_alloted)
                    {
                        if (1 <= DateTime.Now.Month && DateTime.Now.Month <= 3)
                        {
                            if (4 <= leave.Start_Date.Month && leave.Start_Date.Month <= 6)
                            {
                                if (number_of_days < account.leaves_alloted + 5)
                                {
                                }
                            }
                            else if (7 <= leave.Start_Date.Month && leave.Start_Date.Month <= 9)
                            {
                                if (number_of_days < account.leaves_alloted + 10)
                                {
                                }
                            }
                        }
                        else if (4 <= DateTime.Now.Month && DateTime.Now.Month <= 6)
                        {
                            if (7 <= leave.Start_Date.Month && leave.Start_Date.Month <= 9)
                            {
                                if (number_of_days < account.leaves_alloted + 5)
                                {
                                }
                            }
                            else if (10 <= leave.Start_Date.Month && leave.Start_Date.Month <= 12)
                            {
                                if (number_of_days < account.leaves_alloted + 10)
                                {
                                }
                            }
                        }
                        else if (7 <= DateTime.Now.Month && DateTime.Now.Month <= 9)
                        {
                            if (10 <= leave.Start_Date.Month && leave.Start_Date.Month <= 12)
                            {
                                if (number_of_days < account.leaves_alloted + 5)
                                {
                                }
                            }
                            else if (1 <= leave.Start_Date.Month && leave.Start_Date.Month <= 3)
                            {
                                if (account.leaves_alloted > 10)
                                {
                                }
                            }
                        }
                    }
                    else
                    {
                        message        = "Leave Applied for is greater than your Leave Balance";
                        ViewBag.Status = false;
                    }
                }
            }
            else if (leave.End_Date < leave.Start_Date)
            {
                message = "End Date should be greater then Start Date";
                status  = false;
            }
            else if ((leave.End_Date == leave.Start_Date) && (leave.Start_Date == null))
            {
                message = "Cannot pass Null in Required Field";
                status  = false;
            }
            else if (leave.End_Date == leave.Start_Date)
            {
                try
                {
                    if (leave.Start_Date.DayOfWeek == DayOfWeek.Saturday || leave.Start_Date.DayOfWeek == DayOfWeek.Sunday)
                    {
                        ViewBag.Message = "You are applying Leave on day which is already a Holiday";
                        return(View());
                    }
                    //else
                    {
                        leave.Start_Date = leave.Start_Date.Date;
                        leave.End_Date   = leave.End_Date.Date;

                        leave.Number_of_Days = 1;
                        if (DateTime.Now.Date.Kind == DateTimeKind.Utc)
                        {
                            leave.Leave_apply_date = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.Date, indian_zone);
                        }
                        else if (DateTime.Now.Date.Kind != DateTimeKind.Utc)
                        {
                            leave.Leave_apply_date = DateTime.Now.Date;
                        }
                        leave.Status       = "Pending on Approvers";
                        leave.Employe_name = Session["userName"].ToString();
                        leave.Employee_Id  = (Session["userID"].ToString());
                        using (VC_LMSEntities f = new VC_LMSEntities())
                        {
                            var    row          = f.UsersTables.Where(m => m.ROLES == "HR").FirstOrDefault();
                            string EmailID      = row.EMAIL;
                            string employeename = leave.Employe_name;
                            int    days_Leave   = leave.Number_of_Days;
                            SendverificationLinkEmail(EmailID, employeename, days_Leave, row.FIRST_NAME, leave.LeaveType);
                            var emp_id    = Session["userID"].ToString();
                            var apporvers = f.approvers.Where(y => y.Emplyoee_id == emp_id).FirstOrDefault();
                            if (apporvers != null)
                            {
                                foreach (var item in f.approvers)
                                {
                                    if (item.Emplyoee_id == emp_id)
                                    {
                                        var approvr = f.UsersTables.Where(q => q.EMPLOYEE_ID == item.approver_id).FirstOrDefault();
                                        SendverificationLinkEmail(approvr.EMAIL, employeename, days_Leave, approvr.FIRST_NAME, leave.LeaveType);
                                    }
                                }
                            }
                            f.Leaves.Add(leave);
                            f.SaveChanges();
                            ModelState.Clear();
                            message        = "Successfully Applied";
                            ViewBag.Status = status;
                        }
                    }
                }

                catch (Exception ex)
                {
                    ViewBag.Message = "Exclude Special Characters from Reason";
                    return(View());
                }
            }
            ViewBag.Message = message;
            ViewBag.Status  = status;
            ModelState.Clear();
            return(View());
        }
Exemple #5
0
        public ActionResult Edit(int id, LeaveManagementSystemValueCreed.Models.Leave leave)
        {
            int n = 0;

            //try
            VC_LMSEntities j            = new VC_LMSEntities();
            var            approval_tbl = j.approvals.Where(x => x.Leave_id == leave.ID && x.status == "Approved By HR").FirstOrDefault();

            if (approval_tbl != null)
            {
                int            leave_id        = leave.ID;
                VC_LMSEntities d               = new VC_LMSEntities();
                var            user_id         = d.UsersTables.Where(v => v.EMPLOYEE_ID == leave.Employee_Id).FirstOrDefault();
                var            approver_number = d.approvers.Where(w => w.Emplyoee_id == leave.Employee_Id).FirstOrDefault();
                if (approver_number != null)
                {
                    leave.Status         = "Requested Approvers For Cancellation";
                    d.Entry(leave).State = System.Data.Entity.EntityState.Modified;
                    d.SaveChanges();
                }
                else
                {
                    leave.Status         = "Cancellation Pending on HR";
                    d.Entry(leave).State = System.Data.Entity.EntityState.Modified;
                    d.SaveChanges();
                }
                return(RedirectToAction("Leave", "Employee"));
            }
            else
            {
                VC_LMSEntities l = new VC_LMSEntities();
                if (leave.Status == "Cancel")
                {
                    leave.Status = "Cancelled";

                    l.Entry(leave).State = System.Data.Entity.EntityState.Modified;
                    l.SaveChanges();
                    return(RedirectToAction("Leave", "Employee"));
                }
                else
                {
                    using (VC_LMSEntities db = new VC_LMSEntities())
                    {
                        var indian_zone = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
                        if (DateTime.Now.Date.Kind == DateTimeKind.Utc)
                        {
                            if (leave.Start_Date.Subtract(TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.Date, indian_zone)).Days > 360)
                            {
                                ViewBag.Message = "Cannot Apply for such date,as it is too Far";
                                return(View());
                            }
                        }
                        else
                        {
                            if (leave.Start_Date.Subtract(DateTime.Now.Date).Days > 360)
                            {
                                ViewBag.Message = "Cannot Apply for such date,as it is too Far";
                                return(View());
                            }
                        }
                        bool   status  = false;
                        string message = "";
                        if (DateTime.Now.Date.Kind != DateTimeKind.Utc)
                        {
                            var datediff = DateTime.Now.Date.Subtract(leave.End_Date);
                            if (datediff.TotalDays > 0)
                            {
                                ViewBag.Message = "Cannot Apply Leave  if End Date is in the Past";
                                ViewBag.Status  = false;
                                return(View());
                            }
                        }
                        else if (DateTime.Now.Date.Kind == DateTimeKind.Utc)
                        {
                            var datediff = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.Date, indian_zone).Subtract(leave.End_Date);
                            if (datediff.TotalDays > 0)
                            {
                                ViewBag.Message = "Cannot Apply Leave  if End Date is in the Past";
                                ViewBag.Status  = false;
                                return(View());
                            }
                        }
                        if (leave.End_Date > leave.Start_Date)
                        {
                            int            c  = 0;
                            VC_LMSEntities dd = new VC_LMSEntities();
                            foreach (var item in dd.Leaves)
                            {
                                if ((Session["userID"].ToString()) == item.Employee_Id)
                                {
                                    if ((item.Start_Date < leave.Start_Date) && (leave.End_Date < item.End_Date) && (item.Status != "Cancelled") && leave.ID != item.ID)
                                    {
                                        ViewBag.Message = "Leave range falling under Another Leave Range ";
                                        ViewBag.Status  = false;
                                        ModelState.Clear();
                                        return(View());
                                    }
                                    else if ((item.Start_Date < leave.Start_Date) && (leave.End_Date < item.End_Date) && (item.Status != "Cancelled") && leave.ID != item.ID)
                                    {
                                        ViewBag.Message = "Leave date conflict,Please Apply after previous leave Ends ";
                                        ViewBag.Status  = false;
                                        ModelState.Clear();
                                        return(View());
                                    }
                                    else if ((item.Start_Date < leave.Start_Date) && (leave.Start_Date < item.End_Date) && (item.Status != "Cancelled") && leave.ID != item.ID)
                                    {
                                        ViewBag.Message = "Leave date conflict,Please Apply after previous leave Ends,or Edit ";
                                        ViewBag.Status  = false;
                                        ModelState.Clear();
                                        return(View());
                                    }

                                    if ((leave.Start_Date == item.Start_Date || leave.End_Date == item.End_Date) && item.Status != "Cancelled" && leave.ID != item.ID)
                                    {
                                        ViewBag.Message = "Matching Date For Already Applied Leave Found,Please Cancel that Leave ";
                                        ViewBag.Status  = false;
                                        ModelState.Clear();
                                        return(View());
                                    }
                                }
                                if (item.Employee_Id == (Session["userID"].ToString()) && (item.Status == "Pending on Manager" || item.Status == "Approved By Manager" || item.Status == "Pending on Approvers" || item.Status == "Approved By Approvers") && leave.ID != item.ID)
                                {
                                    c += item.Number_of_Days;
                                }
                            }
                            var x       = (Session["userID"].ToString());
                            var account = dd.UsersTables.Where(a => a.EMPLOYEE_ID == x).FirstOrDefault();

                            if (account.leaves_alloted == 0)
                            {
                                message = "Sorry Your Leave Balance is Zero and you cannot apply";
                                status  = false;
                            }
                            else
                            {
                                int e              = 0;
                                var number_of_day  = leave.End_Date.Date.Subtract(leave.Start_Date);
                                int number_of_days = 0;
                                number_of_days = number_of_day.Days + 1;
                                int d = 0;
                                for (DateTime i = leave.Start_Date; i < leave.End_Date; i = i.AddDays(1))
                                {
                                    if (i.DayOfWeek == DayOfWeek.Saturday || i.DayOfWeek == DayOfWeek.Sunday)
                                    {
                                        e = e + 1;
                                    }
                                }

                                number_of_days = number_of_days - e;

                                if ((c + number_of_days > account.leaves_alloted))
                                {
                                    message         = "Already Applied or Approved leaves Exceeds Your Leave Balance";
                                    status          = false;
                                    ViewBag.Message = message;
                                    ViewBag.Status  = status;
                                }
                                else if (number_of_days < account.leaves_alloted)
                                {
                                    try
                                    {
                                        leave.Start_Date = leave.Start_Date.Date;
                                        leave.End_Date   = leave.End_Date.Date;


                                        if (DateTime.Now.Date.Kind == DateTimeKind.Utc)
                                        {
                                            leave.Leave_apply_date = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.Date, indian_zone);
                                        }
                                        else if (DateTime.Now.Date.Kind != DateTimeKind.Utc)
                                        {
                                            leave.Leave_apply_date = DateTime.Now.Date;
                                        }
                                        VC_LMSEntities vc = new VC_LMSEntities();
                                        int            k  = 0;
                                        foreach (var item in vc.approvers)
                                        {
                                            if (item.Emplyoee_id == (Session["userID"].ToString()))
                                            {
                                                k++;
                                            }
                                        }
                                        if (k > 0)
                                        {
                                            leave.Status = "Pending on Approvers";
                                        }
                                        else if (k == 0)
                                        {
                                            leave.Status = "Pending on HR";
                                        }
                                        leave.Number_of_Days = number_of_days;
                                        leave.Employe_name   = Session["userName"].ToString();
                                        leave.Employee_Id    = (Session["userID"].ToString());
                                        using (VC_LMSEntities f = new VC_LMSEntities())
                                        {
                                            var    row          = f.UsersTables.Where(m => m.ROLES == "HR").FirstOrDefault();
                                            string EmailID      = row.EMAIL;
                                            string employeename = leave.Employe_name;
                                            //SendverificationLinkEmail(EmailID, employeename);
                                            //var userinfo = f.UsersTables.Where(s => s.EMPLOYEE_ID == leave.Employee_Id).FirstOrDefault();
                                            //var row2 = f.UsersTables.Where(m => m.EMPLOYEE_ID == userinfo.manager_id).FirstOrDefault();
                                            //EmailID = row2.EMAIL;
                                            //SendverificationLinkEmail(EmailID, employeename);

                                            l.Entry(leave).State = System.Data.Entity.EntityState.Modified;
                                            l.SaveChanges();
                                            message        = "Successfully Applied";
                                            ViewBag.Status = status;
                                            return(RedirectToAction("Index", "Employee"));
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        ViewBag.Message = "Exclude Special Characters from Reason";
                                        return(View());
                                    }
                                }
                                else
                                {
                                    message        = "Leave Applied for is greater than your Leave Balance";
                                    ViewBag.Status = false;
                                }
                            }
                        }
                        else if (leave.End_Date < leave.Start_Date)
                        {
                            message = "End Date should be greater then Start Date";
                            status  = false;
                        }
                        else if ((leave.End_Date == leave.Start_Date) && (leave.Start_Date == null))
                        {
                            message = "Cannot pass Null in Required Field";
                            status  = false;
                        }
                        else if (leave.End_Date == leave.Start_Date)
                        {
                            try
                            {
                                if (leave.Start_Date.DayOfWeek == DayOfWeek.Saturday || leave.Start_Date.DayOfWeek == DayOfWeek.Sunday)
                                {
                                    ViewBag.Message = "You are applying Leave on day which is already a Holiday";
                                    return(View());
                                }
                                //else

                                leave.Start_Date = leave.Start_Date.Date;
                                leave.End_Date   = leave.End_Date.Date;

                                leave.Number_of_Days = 1;
                                if (DateTime.Now.Date.Kind == DateTimeKind.Utc)
                                {
                                    leave.Leave_apply_date = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.Date, indian_zone);
                                }
                                else if (DateTime.Now.Date.Kind != DateTimeKind.Utc)
                                {
                                    leave.Leave_apply_date = DateTime.Now.Date;
                                }
                                leave.Status       = "Pending on Manager";
                                leave.Employe_name = Session["userName"].ToString();
                                leave.Employee_Id  = (Session["userID"].ToString());
                                using (VC_LMSEntities f = new VC_LMSEntities())
                                {
                                    f.Entry(leave).State = System.Data.Entity.EntityState.Modified;
                                    f.SaveChanges();
                                    message        = "Successfully Applied";
                                    ViewBag.Status = status;
                                    return(RedirectToAction("Index", "Employee"));
                                }
                            }

                            catch (Exception ex)
                            {
                                ViewBag.Message = "Exclude Special Characters from Reason";
                                return(View());
                            }
                        }



                        ViewBag.Message = message;
                        ViewBag.Status  = status;
                        ModelState.Clear();
                        return(View());
                    }
                }
            }
        }
Exemple #6
0
        public ActionResult Create(LeaveManagementSystemValueCreed.Models.UsersTable usr)
        {
            try
            {
                bool t = usr.EMAIL.Contains("valuecreed.com");
                if (t == false)
                {
                    ViewBag.Message = "Please Enter internal Email of ValueCreed";
                    return(View());
                }
                VC_LMSEntities e = new VC_LMSEntities();
                //var managername = e.UsersTables.Where(x => x.EMPLOYEE_ID == usr.manager_id).FirstOrDefault();
                //if (managername == null)
                //{
                //    ViewBag.Message = "Please Select Manager ";
                //    return View();
                //}
                //usr.manager_name = managername.FIRST_NAME;
                //var row = e.UsersTables.Where(x => x.EMPLOYEE_ID == usr.manager_id).FirstOrDefault();

                List <department_tbl> l = new List <department_tbl>();
                List <RolesTable>     r = new List <RolesTable>();
                foreach (var item in e.RolesTables)
                {
                    if (item.NAME != "Admin")
                    {
                        r.Add(item);
                    }
                }
                //ViewData["Manager"] = new SelectList(e.managers, "name", "name");
                ViewData["Department"] = new SelectList(e.department_tbl, "DEPARTMENT", "DEPARTMENT");
                ViewData["Roles"]      = new SelectList(r, "NAME", "NAME");
                VC_LMSEntities d = new VC_LMSEntities();
                if (1 <= usr.Emp_start_date.Month && usr.Emp_start_date.Month < 3)
                {
                    if (usr.Emp_start_date.Date < new DateTime(usr.Emp_start_date.Year, 1, 15))
                    {
                        usr.leaves_alloted = 5;
                    }
                    else if (usr.Emp_start_date.Date > new DateTime(usr.Emp_start_date.Year, 1, 15) && usr.Emp_start_date.Date < new DateTime(usr.Emp_start_date.Year, 2, 15))
                    {
                        usr.leaves_alloted = 3;
                    }
                    else if (usr.Emp_start_date.Date > new DateTime(usr.Emp_start_date.Year, 2, 15))
                    {
                        usr.leaves_alloted = 1;
                    }
                }
                else if (4 <= usr.Emp_start_date.Month && usr.Emp_start_date.Month < 6)
                {
                    if (usr.Emp_start_date.Date < new DateTime(usr.Emp_start_date.Year, 4, 15))
                    {
                        usr.leaves_alloted = 5;
                    }
                    else if (usr.Emp_start_date.Date > new DateTime(usr.Emp_start_date.Year, 4, 15) && usr.Emp_start_date.Date < new DateTime(usr.Emp_start_date.Year, 5, 15))
                    {
                        usr.leaves_alloted = 3;
                    }
                    else if (usr.Emp_start_date.Date > new DateTime(usr.Emp_start_date.Year, 5, 15))
                    {
                        usr.leaves_alloted = 1;
                    }
                }
                else if (7 <= usr.Emp_start_date.Month && usr.Emp_start_date.Month < 9)
                {
                    if (usr.Emp_start_date.Date < new DateTime(usr.Emp_start_date.Year, 7, 15))
                    {
                        usr.leaves_alloted = 5;
                    }
                    else if (usr.Emp_start_date.Date > new DateTime(usr.Emp_start_date.Year, 7, 15) && usr.Emp_start_date.Date < new DateTime(usr.Emp_start_date.Year, 8, 15))
                    {
                        usr.leaves_alloted = 3;
                    }
                    else if (usr.Emp_start_date.Date > new DateTime(usr.Emp_start_date.Year, 8, 15))
                    {
                        usr.leaves_alloted = 1;
                    }
                }
                else if (10 <= usr.Emp_start_date.Month && usr.Emp_start_date.Month < 12)
                {
                    if (usr.Emp_start_date.Date < new DateTime(usr.Emp_start_date.Year, 10, 15))
                    {
                        usr.leaves_alloted = 5;
                    }
                    else if (usr.Emp_start_date.Date > new DateTime(usr.Emp_start_date.Year, 10, 15) && usr.Emp_start_date.Date < new DateTime(usr.Emp_start_date.Year, 11, 15))
                    {
                        usr.leaves_alloted = 3;
                    }
                    else if (usr.Emp_start_date.Date > new DateTime(usr.Emp_start_date.Year, 11, 15))
                    {
                        usr.leaves_alloted = 1;
                    }
                }
                using (VC_LMSEntities dd = new VC_LMSEntities())
                {
                    var user = dd.UsersTables.Where(x => x.EMAIL == usr.EMAIL).FirstOrDefault();
                    if (user != null)
                    {
                        ViewBag.Message = "Email Already Present";
                        return(View());
                    }



                    d.UsersTables.Add(usr);
                    d.SaveChanges();
                }

                ModelState.Clear();
                ViewBag.Meassage = "Creation Success";
                return(View());
            }
            catch (Exception ex)
            {
                ViewBag.Message = "Some Invalid Values have been given,Please Retry";
                return(View());
            }
        }
Exemple #7
0
        public ActionResult LeaveApply(LeaveManagementSystemValueCreed.Models.Leave leave)
        {
            var indian_zone = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");

            if (DateTime.Now.Date.Kind == DateTimeKind.Utc)
            {
                if (leave.Start_Date.Subtract(TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.Date, indian_zone)).Days > 360)
                {
                    ViewBag.Message = "Cannot Apply for such date,as it is too Far";
                    return(View());
                }
            }
            else
            {
                if (leave.Start_Date.Subtract(DateTime.Now.Date).Days > 360)
                {
                    ViewBag.Message = "Cannot Apply for such date,as it is too Far";
                    return(View());
                }
            }
            bool   status  = false;
            string message = "";

            if (DateTime.Now.Date.Kind != DateTimeKind.Utc)
            {
                var datediff = DateTime.Now.Date.Subtract(leave.End_Date);
                if (datediff.TotalDays > 0)
                {
                    ViewBag.Message = "Cannot Apply Leave  if End Date is in the Past";
                    ViewBag.Status  = false;
                    return(View());
                }
            }
            else if (DateTime.Now.Date.Kind == DateTimeKind.Utc)
            {
                var datediff = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.Date, indian_zone).Subtract(leave.End_Date);
                if (datediff.TotalDays > 0)
                {
                    ViewBag.Message = "Cannot Apply Leave  if End Date is in the Past";
                    ViewBag.Status  = false;
                    return(View());
                }
            }
            if (leave.End_Date > leave.Start_Date)
            {
                int            c  = 0;
                VC_LMSEntities dd = new VC_LMSEntities();
                foreach (var item in dd.Leaves)
                {
                    if ((Session["userID"].ToString()) == item.Employee_Id)
                    {
                        if ((item.Start_Date < leave.Start_Date) && (leave.End_Date < item.End_Date) && (item.Status != "Cancelled" || item.Status == "Approved By Approver" || item.Status == "Approved By Manager"))
                        {
                            ViewBag.Message = "Leave range falling under Another Leave Range ";
                            ViewBag.Status  = false;
                            ModelState.Clear();
                            return(View());
                        }
                        else if ((item.Start_Date < leave.Start_Date) && (leave.End_Date < item.End_Date) && (item.Status != "Cancelled" || item.Status == "Approved By Approver" || item.Status == "Approved By Manager"))
                        {
                            ViewBag.Message = "Leave date conflict,Please Apply after previous leave Ends ";
                            ViewBag.Status  = false;
                            ModelState.Clear();
                            return(View());
                        }
                        else if ((item.Start_Date < leave.Start_Date) && (leave.Start_Date < item.End_Date) && (item.Status != "Cancelled" || item.Status == "Approved By Approver" || item.Status == "Approved By Manager"))
                        {
                            ViewBag.Message = "Leave date conflict,Please Apply after previous leave Ends,or Edit ";
                            ViewBag.Status  = false;
                            ModelState.Clear();
                            return(View());
                        }
                        if ((leave.Start_Date == item.Start_Date || leave.End_Date == item.End_Date) && item.Status != "Cancelled" || item.Status == "Approved By Approver" || item.Status == "Approved By Manager")
                        {
                            ViewBag.Message = "Matching Date For Already Applied Leave Found,Please Edit that Leave,if approved,then applya new Leave ";
                            ViewBag.Status  = false;
                            ModelState.Clear();
                            return(View());
                        }
                    }
                    if (item.Employee_Id == (Session["userID"].ToString()) && (item.Status == "Pending on Manager" || item.Status == "Pending on Approver" || item.Status == "Approved By Approver" || item.Status == "Approved By Manager"))
                    {
                        c += item.Number_of_Days;
                    }
                }
                int x       = Convert.ToInt32(Session["userID"]);
                var account = dd.UsersTables.Where(a => a.EMPLOYEE_ID == x.ToString()).FirstOrDefault();

                if (account.leaves_alloted == 0)
                {
                    message = "Sorry Your Leave Balance is Zero and you cannot apply";
                    //return RedirectToAction("ApplyLeave");
                    status = false;
                }
                else
                {
                    int e              = 0;
                    var number_of_day  = leave.End_Date.Date.Subtract(leave.Start_Date);
                    int number_of_days = 0;
                    number_of_days = number_of_day.Days;
                    int d = 0;
                    for (DateTime i = leave.Start_Date; i < leave.End_Date; i = i.AddDays(1))
                    {
                        if (i.DayOfWeek.ToString() == "Saturday" || i.DayOfWeek.ToString() == "Sunday")
                        {
                            e++;
                        }
                    }
                    number_of_days = number_of_days - e;

                    if ((c + number_of_days > account.leaves_alloted))
                    {
                        message         = "Already Applied leaves Exceeds Your Leave Balance";
                        status          = false;
                        ViewBag.Message = message;
                        ViewBag.Status  = status;
                    }
                    else if (number_of_days <= account.leaves_alloted)
                    {
                        try
                        {
                            leave.Start_Date = leave.Start_Date.Date;
                            leave.End_Date   = leave.End_Date.Date;

                            leave.Number_of_Days   = number_of_days + 1;
                            leave.Leave_apply_date = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.Date, indian_zone);
                            leave.Status           = "Pending on Approvers";
                            leave.Employe_name     = Session["userName"].ToString();
                            leave.Employee_Id      = (Session["userID"].ToString());
                            using (VC_LMSEntities f = new VC_LMSEntities())
                            {
                                f.Leaves.Add(leave);
                                f.SaveChanges();
                                ModelState.Clear();
                                message        = "Successfully Applied";
                                ViewBag.Status = status;
                            }
                        }
                        catch (Exception ex)
                        {
                            ViewBag.Message = "Exclude Special Characters from Reason";
                            return(View());
                        }
                    }
                    else
                    {
                        message        = "Leave Applied for is greater than your Leave Balance";
                        ViewBag.Status = false;
                    }
                }
            }
            else if (leave.End_Date < leave.Start_Date)
            {
                message = "End Date should be greater then Start Date";
                status  = false;
            }
            else if ((leave.End_Date == leave.Start_Date) && (leave.Start_Date == null))
            {
                message = "Cannot pass Null in Required Field";
                status  = false;
            }
            else if (leave.End_Date == leave.Start_Date)
            {
                try
                {
                    leave.Start_Date = leave.Start_Date.Date;
                    leave.End_Date   = leave.End_Date.Date;

                    leave.Number_of_Days   = 1;
                    leave.Leave_apply_date = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.Date, indian_zone);
                    leave.Status           = "Pending on Approvers";
                    leave.Employe_name     = Session["userName"].ToString();
                    leave.Employee_Id      = (Session["userID"].ToString());
                    using (VC_LMSEntities f = new VC_LMSEntities())
                    {
                        f.Leaves.Add(leave);
                        f.SaveChanges();
                        ModelState.Clear();
                        message        = "Successfully Applied";
                        ViewBag.Status = status;
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "Exclude Special Characters from Reason";
                    return(View());
                }
            }
            ViewBag.Message = message;
            ViewBag.Status  = status;
            ModelState.Clear();
            return(View());
        }
        public ActionResult Edit(int id, LeaveManagementSystemValueCreed.Models.Leave leaf)
        {
            try
            {
                VC_LMSEntities h            = new VC_LMSEntities();
                var            approval_row = h.approvals.Where(r => r.Leave_id == leaf.ID && r.status == "Approved By HR").FirstOrDefault();
                if (approval_row != null)
                {
                    if (leaf.Status == "Approved")
                    {
                        leaf.Status         = "Cancellation Pending on HR";
                        h.Entry(leaf).State = System.Data.Entity.EntityState.Modified;
                        h.SaveChanges();
                        return(RedirectToAction("Index", "Approver"));
                    }
                }


                int c = 0;
                int e = 0;
                if (leaf.Status == "Approved")
                {
                    c++;
                }
                VC_LMSEntities d   = new VC_LMSEntities();
                var            hr1 = d.UsersTables.Where(x => x.EMPLOYEE_ID == leaf.Employee_Id).FirstOrDefault();
                if (leaf.Status == "Approved" && hr1.ROLES == "HR")
                {
                    approval approval2 = new approval();
                    approval2.Aprrover_id = Session["userID"].ToString();
                    approval2.Employee_id = leaf.Employee_Id;
                    approval2.Leave_id    = leaf.ID;
                    approval2.status      = "Approved By  " + Session["Name"].ToString();
                    d.approvals.Add(approval2);

                    leaf.Status         = "Approved";
                    hr1.leaves_alloted  = hr1.leaves_alloted - leaf.Number_of_Days;
                    d.Entry(leaf).State = System.Data.Entity.EntityState.Modified;
                    d.Entry(hr1).State  = System.Data.Entity.EntityState.Modified;
                    d.SaveChanges();
                    return(RedirectToAction("Index", "Approver"));
                }
                foreach (var item in d.approvals)
                {
                    if (item.Leave_id == leaf.ID)
                    {
                        c++;
                    }
                }
                if (leaf.Status == "Approved")
                {
                    var i = leaf.Employee_Id;
                    foreach (var item in d.approvers)
                    {
                        if (item.Emplyoee_id == leaf.Employee_Id)
                        {
                            e++;
                        }
                    }
                    if (c == e)
                    {
                        leaf.Status = "Approved By All Approvers";
                        var hr = d.UsersTables.Where(x => x.EMPLOYEE_ID == leaf.Employee_Id && x.ROLES == "HR").FirstOrDefault();
                        if (hr != null)
                        {
                            hr.leaves_alloted = hr.leaves_alloted - leaf.Number_of_Days;
                            d.Entry(hr).State = System.Data.Entity.EntityState.Modified;
                            approval approval2 = new approval();
                            approval2.Aprrover_id = Session["userID"].ToString();
                            approval2.Employee_id = leaf.Employee_Id;
                            approval2.Leave_id    = leaf.ID;
                            approval2.status      = "Approved By  " + Session["Name"].ToString();
                            d.approvals.Add(approval2);
                            d.SaveChanges();
                        }
                        var emp  = d.UsersTables.Where(x => x.EMPLOYEE_ID == leaf.Employee_Id).FirstOrDefault();
                        var body = "Hello " + emp.FIRST_NAME + ",< br /> <br /> your Leave has been approved by all the Approvers. <br /> <br /> Warm Regards, <br /> LMS Team.";
                        SendverificationLinkEmail(emp.EMAIL, body);
                        var hrmail = d.UsersTables.Where(x => x.ROLES == "HR").FirstOrDefault();
                        body = "Hello  " + hrmail.FIRST_NAME + ",< br /> <br /> Leave application of  " + leaf.Employe_name + "  has been approved by all approvers and now it is pending on you. <br/> <br /> Warm Regards, <br /> LMS Team.";
                        //SendverificationLinkEmail(hrmail.EMAIL, body);
                        approval approval1 = new approval();
                        approval1.Aprrover_id = Session["userID"].ToString();
                        approval1.Employee_id = leaf.Employee_Id;
                        approval1.Leave_id    = leaf.ID;
                        approval1.status      = "Approved By  " + Session["Name"].ToString();
                        d.approvals.Add(approval1);
                        d.SaveChanges();
                    }
                    else
                    {
                        var emp = d.UsersTables.Where(x => x.EMPLOYEE_ID == leaf.Employee_Id).FirstOrDefault();

                        var body = "Hello " + emp.FIRST_NAME + ",< br /> <br />  your Leave has been approved by  " + Session["userName"] + "< br /> <br /> Warm Regards, <br /> LMS Team.";
                        //SendverificationLinkEmail(emp.EMAIL, body);
                        leaf.Status = "Pending on Approvers";
                        approval approval1 = new approval();
                        approval1.Aprrover_id = Session["userID"].ToString();
                        approval1.Employee_id = leaf.Employee_Id;
                        approval1.Leave_id    = leaf.ID;
                        approval1.status      = "Approved By  " + Session["Name"].ToString();
                        d.approvals.Add(approval1);
                        d.SaveChanges();
                    }
                }
                else if (leaf.Status == "Rejected By Approver")
                {
                    approval approval1 = new approval();
                    approval1.Aprrover_id = Session["userID"].ToString();
                    approval1.Employee_id = leaf.Employee_Id;
                    approval1.Leave_id    = leaf.ID;
                    approval1.status      = "Rejected By  " + Session["Name"].ToString();
                    d.approvals.Add(approval1);
                    d.SaveChanges();
                }
                d.Entry(leaf).State = System.Data.Entity.EntityState.Modified;
                d.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ViewBag.Message = "Unable to change the status";
                return(View());
            }
        }