Exemplo n.º 1
0
 public async Task UpdateAsync(EmployeesLog employeesLog)
 {
     if (employeesLog != null)
     {
         _applicationDbContext.Entry(employeesLog).State = EntityState.Modified;
         await _applicationDbContext.SaveChangesAsync();
     }  
 }
Exemplo n.º 2
0
        public async Task<ActionResult> Index(string searchDate)
        {
            IEnumerable<EmployeesLog> employeesLogs = null;
            List<EmployeesLog> employeesList = new List<EmployeesLog>();

            var userDepartment = await _departmentService.GetUserDepartmentsAsync(User.Identity.GetUserId());
            var departments = userDepartment as IList<Department> ?? userDepartment.ToList();
            if (User.IsInRole("ManageDepartmentShift"))
            {
                DateTime startDate = DateTime.Today;
                TimeSpan startTime = new TimeSpan(08, 00, 00);
                foreach (var department in departments)
                {
                    var employesses = await _employeesService.GetEmployessYesterDayByIdAndDateAsync(startDate.Subtract(startTime), department.DepartmentID);
                    foreach (var employess in employesses)
                    {
                        var log = await _employeesLogService.CheckEmployeesLogExitsByStaffCodeAndDateCheckAysnc(employess.StaffCode, startDate);
                        if (log == null)
                        {
                            var employeesLog = new EmployeesLog()
                            {
                                StaffCode = employess.StaffCode,
                                FullName = employess.FullName,
                                DepartmentID = employess.DepartmentID,
                                Note = StringHelper.GetInfo(User.Identity.GetUserName()),
                                CreateBy = User.Identity.GetUserName(),
                                StaffPicture = employess.StaffPicture,
                                DateCheck = startDate,
                                TimeCheck = employess.DateCheck,
                                LeaderApproved = false,
                                ManagerApproved = false,
                                GaComplete = false,
                                ManageDepartmentShiftApproved = false,
                            };
                            try
                            {
                                await _employeesLogService.CreateAsync(employeesLog);
                            }
                            catch (Exception ex)
                            {
                                throw new Exception(ex.Message);
                            }
                        }
                    }
                }

                employeesLogs = await _employeesLogService.GetEmployeesLogsByApprovedAsync("ManageDepartmentShift", DateTime.Today, departments);
            }
            //else if (User.IsInRole("ManageDepartmentShift"))
            //{
            //    employeesLogs = await _employeesLogService.GetEmployeesLogsByApprovedAsync("ManageDepartmentShift", DateTime.Today, departments);
            //}
            if (User.IsInRole("Manager"))
            {
                employeesLogs = await _employeesLogService.GetEmployeesLogsByApprovedAsync("Manager", DateTime.Today, departments);
            }
            if (User.IsInRole("GA"))
            {
                if (!string.IsNullOrEmpty(searchDate))
                {
                    try
                    {
                        DateTime dateSearch = DateTime.ParseExact(searchDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                        employeesLogs = await _employeesLogService.GetEmployeesLogsByApprovedAsync("GA", dateSearch);
                    }
                    catch (Exception ex)
                    {
                        ViewBag.ErrorMessage = $"Invalid date {searchDate}." + ex.Message;
                        employeesLogs = await _employeesLogService.GetEmployeesLogsByApprovedAsync("GA", DateTime.Today.AddYears(10));
                    }
                }
                else
                {
                    employeesLogs = await _employeesLogService.GetEmployeesLogsByApprovedAsync("GA", DateTime.Today);
                }
            }
            if (User.IsInRole("Admin"))
            {
                employeesLogs = await _employeesLogService.GetEmployeesLogsByApprovedAsync("Admin", DateTime.Today);
            }
            return View(employeesLogs);
        }
Exemplo n.º 3
0
 public async Task CreateAsync(EmployeesLog employeesLog)
 {
     if (employeesLog != null)
     {
         _applicationDbContext.EmployeesLogs.Add(employeesLog);
         await _applicationDbContext.SaveChangesAsync();
     }
 }