Exemplo n.º 1
0
        // Author: Lance, Saw
        // return a form to allow dept head to assign an employee as delegate
        public IActionResult CreateNewDelegatedEmployee()
        {
            if (getUserRole().Equals(""))
            {
                return(RedirectToAction("Login", "Login"));
            }
            //Security
            if (!(getUserRole() == DeptRole.DeptHead.ToString() ||
                  getUserRole() == DeptRole.DelegatedEmployee.ToString()))
            {
                if (getUserRole() == DeptRole.Employee.ToString() ||
                    getUserRole() == DeptRole.Contact.ToString() ||
                    getUserRole() == DeptRole.DeptRep.ToString())
                {
                    return(RedirectToAction(_filterService.Filter(getUserRole()), "Dept"));
                }
                else
                {
                    return(RedirectToAction(_filterService.Filter(getUserRole()), "Store"));
                }
            }
            var newDelegatedEmployee = new DelegatedEmployee();

            newDelegatedEmployee.DelegateEmployeeDetails = new List <DelegateEmployeeDetail>();

            int      userId    = (int)HttpContext.Session.GetInt32("Id");
            Employee user      = _dbContext.Employees.SingleOrDefault(x => x.Id == userId);
            int      deptId    = user.Dept.id;
            var      employees = _dbContext.Employees.Where(x => x.Dept.id == deptId && x.Id != userId).ToList();

            foreach (var employee in employees)
            {
                var deDetail = new DelegateEmployeeDetail();
                deDetail.Employee = employee;
                newDelegatedEmployee.DelegateEmployeeDetails.Add(deDetail);
            }
            Console.WriteLine(newDelegatedEmployee);

            TempData["now"] = DateTime.Now.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss");
            ;
            // DateTime now = new DateTime.Now();
            return(View(newDelegatedEmployee));
        }
Exemplo n.º 2
0
        public void PostSelectedEmp([FromBody] DelagatedEmpFromAndroid input)
        {
            var empName   = input.EmpName;
            var startDate = input.StartDate;
            var endDate   = input.EndDate;

            //string iString = input.OrderDate;
            //newPo.OrderDate = DateTime.ParseExact(iString, "yyyy-MM-dd", null);

            var employee             = _dbContext.Employees.SingleOrDefault(x => x.Name == empName);
            var newDelegatedEmployee = new DelegatedEmployee();

            newDelegatedEmployee.Name     = employee.Name;
            employee.Role                 = DeptRole.DelegatedEmployee;
            newDelegatedEmployee.Employee = employee;
            //newDelegatedEmployee.StartDate = Convert.ToDateTime(startDate);
            //newDelegatedEmployee.EndDate = Convert.ToDateTime(endDate);
            newDelegatedEmployee.StartDate        = DateTime.ParseExact(startDate, "dd-MM-yyyy", null);
            newDelegatedEmployee.EndDate          = DateTime.ParseExact(endDate, "dd-MM-yyyy", null);
            newDelegatedEmployee.delegationStatus = DelegationStatus.Selected;
            SaveEmployeeDelegation(newDelegatedEmployee);
            _dbContext.Add(newDelegatedEmployee);
            _dbContext.SaveChanges();
        }
Exemplo n.º 3
0
        // Author: Benedict, Kyaw Thiha, Saw Htet Kyaw
        // Allows the user to login
        public IActionResult Login(string username, string hashPasswd)
        {
            if (username == null)
            {
                TempData["error"] = "Username is required!";
                return(RedirectToAction("Index"));
            }
            if (hashPasswd == "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=")
            {
                TempData["error"] = "Password is required!";
                return(RedirectToAction("Index"));
            }
            Employee user = _dbContext.Employees.FirstOrDefault(u => u.Username == username);

            if (user == null)
            {
                TempData["error"] = "Username is wrong!";
                return(RedirectToAction("Index"));
            }

            if (user.Password != hashPasswd)
            {
                TempData["error"] = "Password is wrong!";
                return(RedirectToAction("Index"));
            }


            HttpContext.Session.SetString("username", user.Name);
            HttpContext.Session.SetString("loginName", user.Username);
            HttpContext.Session.SetInt32("Id", user.Id);
            HttpContext.Session.SetString("jobTitle", user.JobTitle.ToString());
            HttpContext.Session.SetString("Role", user.Role.ToString());

            if (user.Role == DeptRole.StoreClerk)
            {
                return(RedirectToAction("BarChart", "Store"));
            }
            else if (user.Role == DeptRole.StoreSupervisor || user.Role == DeptRole.StoreManager)
            {
                return(RedirectToAction("AuthorizeAdjustmentVoucherList", "Store"));
            }
            if (user.Role == DeptRole.DeptHead)
            {
                return(RedirectToAction("DeptHeadRequisitionList", "Dept"));
            }
            if ((user.Role == DeptRole.Employee) || (user.Role == DeptRole.Contact))
            {
                return(RedirectToAction("EmployeeRequisitionList", "Dept"));
            }
            if (user.Role == DeptRole.DeptRep)
            {
                return(RedirectToAction("EmployeeRequisitionList", "Dept"));
            }
            if (user.Role == DeptRole.DelegatedEmployee)
            {
                DelegatedEmployee dEmp = _dbContext.DelegatedEmployees.SingleOrDefault(x => x.delegationStatus == DelegationStatus.Selected && x.Employee.Id == user.Id);
                if (dEmp != null)
                {
                    DateTime startDate = dEmp.StartDate;
                    DateTime endDate   = dEmp.EndDate;
                    if (endDate < DateTime.Now)
                    {
                        dEmp.delegationStatus = DelegationStatus.Cancelled;
                        user.Role             = user.JobTitle;
                        _dbContext.SaveChanges();
                        HttpContext.Session.SetString("Role", user.Role.ToString());
                        return(RedirectToAction("EmployeeRequisitionList", "Dept"));
                    }
                    else if (startDate > DateTime.Now)
                    {
                        HttpContext.Session.SetString("delegationStatus", "TBD");
                        user.Role = user.JobTitle;
                        _dbContext.SaveChanges();
                        HttpContext.Session.SetString("Role", user.Role.ToString());
                        return(RedirectToAction("EmployeeRequisitionList", "Dept"));
                    }
                }
                return(RedirectToAction("DeptHeadRequisitionList", "Dept"));
            }

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 4
0
        // Author: Lance, Saw
        // update an employee as a delegate in the database
        public IActionResult SaveEmployeeDelegation(DelegatedEmployee delegatedEmployee)
        {
            if (getUserRole().Equals(""))
            {
                return(RedirectToAction("Login", "Login"));
            }
            //Security
            if (!(getUserRole() == DeptRole.DeptHead.ToString() ||
                  getUserRole() == DeptRole.DelegatedEmployee.ToString()))
            {
                if (getUserRole() == DeptRole.Employee.ToString() ||
                    getUserRole() == DeptRole.Contact.ToString() ||
                    getUserRole() == DeptRole.DeptRep.ToString())
                {
                    return(RedirectToAction(_filterService.Filter(getUserRole()), "Dept"));
                }
                else
                {
                    return(RedirectToAction(_filterService.Filter(getUserRole()), "Store"));
                }
            }
            //for validate double create
            var val   = _dbContext.DelegatedEmployees.ToList();
            int count = val.Count;

            //extend
            if (delegatedEmployee.Id != 0)
            {
                var dEmp = _dbContext.DelegatedEmployees.SingleOrDefault(x => x.Id == delegatedEmployee.Id);

                if (delegatedEmployee.EndDate < dEmp.EndDate)
                {
                    {
                        TempData["error"] = "Please select a later date";
                        return(RedirectToAction("ExtendEmployeeDelegation", new { Id = delegatedEmployee.Id }));
                    }
                }
                dEmp.EndDate          = delegatedEmployee.EndDate;
                dEmp.delegationStatus = DelegationStatus.Extended;

                MailAddress FromEmail   = new MailAddress("*****@*****.**", "Dept head");
                MailAddress ToEmail     = new MailAddress("*****@*****.**", "Dept Employee");
                string      Subject     = "Extension of delegation period";
                string      MessageBody = "Your delegation has been extended to " + dEmp.EndDate;

                EmailService.SendEmail(FromEmail, ToEmail, Subject, MessageBody);

                _dbContext.SaveChanges();

                return(RedirectToAction("DelegatedEmployeeList"));
            }
            else if (val[count - 1].EndDate > DateTime.Now && val[count - 1].delegationStatus != DelegationStatus.Cancelled)
            {
                TempData["error"] = "You already have a existing record";
                return(RedirectToAction("CreateNewDelegatedEmployee"));
            }
            else
            {
                var employee             = _dbContext.Employees.SingleOrDefault(x => x.Id == delegatedEmployee.Employee.Id);
                var newDelegatedEmployee = new DelegatedEmployee();
                newDelegatedEmployee.Name = employee.Name;
                if (delegatedEmployee.StartDate == Convert.ToDateTime("1 / 1 / 0001 12:00:00 am"))
                {
                    TempData["error"] = "Please fill Start Date";
                    return(RedirectToAction("CreateNewDelegatedEmployee"));
                }
                else if (delegatedEmployee.EndDate == Convert.ToDateTime("1 / 1 / 0001 12:00:00 am"))
                {
                    TempData["error"] = "Please fill End Date";
                    return(RedirectToAction("CreateNewDelegatedEmployee"));
                }
                else if (delegatedEmployee.StartDate > delegatedEmployee.EndDate)
                {
                    TempData["error"] = "Your start date is after end date";
                    return(RedirectToAction("CreateNewDelegatedEmployee"));
                }
                else if (delegatedEmployee.StartDate < DateTime.Now.AddDays(-1) || delegatedEmployee.EndDate < DateTime.Now)
                {
                    TempData["error"] = "Cannot select past date";
                    return(RedirectToAction("CreateNewDelegatedEmployee"));
                }
                newDelegatedEmployee.StartDate        = delegatedEmployee.StartDate;
                newDelegatedEmployee.EndDate          = delegatedEmployee.EndDate;
                newDelegatedEmployee.delegationStatus = DelegationStatus.Selected;
                newDelegatedEmployee.Employee         = employee;
                newDelegatedEmployee.Employee.Role    = DeptRole.DelegatedEmployee;
                MailAddress FromEmail   = new MailAddress("*****@*****.**", "Dept head");
                MailAddress ToEmail     = new MailAddress("*****@*****.**", "Dept Employee");
                string      Subject     = "Selected to stand in for dept head";
                string      MessageBody = "You have been selected to stand in for dept head from "
                                          + newDelegatedEmployee.StartDate + " to " + newDelegatedEmployee.EndDate;

                EmailService.SendEmail(FromEmail, ToEmail, Subject, MessageBody);

                employee.Role = DeptRole.DelegatedEmployee;
                newDelegatedEmployee.Employee = employee;

                _dbContext.Add(newDelegatedEmployee);

                _dbContext.SaveChanges();

                return(RedirectToAction("DelegatedEmployeeList"));
            }
        }