Esempio n. 1
0
 public async Task<ActionResult> Index(SearchBarcode model)
 {
     if (ModelState.IsValid)
     {
         
         var userDepartment = await _userDepartmentsService.GetUserDepartmentsAsync(User.Identity.GetUserId());
         var user = await _bioStarService.GetUserById(model.SearchKey);
         if (user != null)
         {
             var departments = userDepartment as IList<Department> ?? userDepartment.ToList();
             var employes = new Employess()
             {
                 StaffCode = user.sUserID,
                 FullName = user.sUserName,
                 DepartmentID = departments.First().DepartmentID,
                 DateCheck = DateTime.Now,
                 LeaderApproved = false,
                 ManagerApproved = false,
                 GaComplete = false,
                 Note = StringHelper.GetInfo(User.Identity.GetUserName()),
             };
             try
             {
                 var employesCheck = await _employeesService.GetEmployessByIdAndDateAsync(model.SearchKey, DateTime.Now, departments.First().DepartmentID);
                 if (employesCheck == null)
                 {
                     await _employeesService.CreateAsync(employes);
                     model = new SearchBarcode()
                     {
                         SearchKey = string.Empty,
                     };
                     ModelState.Clear();
                     return View(model);
                 }
                 model = new SearchBarcode()
                 {
                     SearchKey = string.Empty,
                 };
                 ModelState.Clear();
                 ModelState.AddModelError("SearchKey", "Error!");
                 return View(model);
             }
             catch (Exception ex)
             {
                 model = new SearchBarcode()
                 {
                     SearchKey = string.Empty,
                 };
                 ModelState.Clear();
                 ModelState.AddModelError("SearchKey", ex.Message);
                 return View(model);
             }
         }
         model = new SearchBarcode()
         {
             SearchKey = string.Empty,
         };
         ModelState.Clear();
         ModelState.AddModelError("SearchKey", "Error! User not exits.");
         return View(model);
     }
     return View(model);
 }
Esempio n. 2
0
        public async Task<ActionResult> InputBarcode(SearchBarcode model)
        {
            if (ModelState.IsValid)
            {
                string staffCode = StringHelper.LengthStaffCode(model.SearchKey);
                var staff = await _gaService.GetStaffByCode(staffCode);
                if (staff != null)
                {
                    Employess employess = new Employess()
                    {
                        StaffCode = staff.StaffCode,
                        FullName = staff.FullName,
                        DepartmentID = staff.DeptCode,
                        CreateBy = staffCode,
                        StaffPicture = staff.StaffPicture,
                        DateCheck = DateTime.Now,
                        LeaderApproved = false,
                        ManagerApproved = false,
                        GaComplete = false,
                        Note = StringHelper.GetInfo(staffCode),
                    };

                    try
                    {
                        var employesCheck = await _employeesService.GetEmployessByIdAndDateAsync(model.SearchKey, DateTime.Now);
                        if (employesCheck == null)
                        {
                            await _employeesService.CreateAsync(employess);
                            ViewBag.SuccessMessage = $"Input user {staffCode} successful!";
                            model = new SearchBarcode()
                            {
                                SearchKey = string.Empty,
                            };
                            ModelState.Clear();
                            return View(model);
                        }
                        model = new SearchBarcode()
                        {
                            SearchKey = string.Empty,
                        };
                        ModelState.Clear();
                        ModelState.AddModelError("SearchKey", $"Error! User {staffCode} already exists.\n" +
                                                              $"Tên: {employesCheck.FullName} \n" +
                                                              $"Input time: {employesCheck.DateCheck.ToShortTimeString()}");
                        return View(model);
                    }
                    catch (Exception ex)
                    {
                        model = new SearchBarcode()
                        {
                            SearchKey = string.Empty,
                        };
                        ModelState.Clear();
                        ModelState.AddModelError("SearchKey", ex.Message);
                        return View(model);
                    }
                }
                model = new SearchBarcode()
                {
                    SearchKey = string.Empty,
                };
                ModelState.Clear();
                ModelState.AddModelError("SearchKey", $"Error! User {staffCode} not exits in database.");
                return View(model);
            }
            return View(model);
        }