public async Task <JsonResult> GroupSchedule(GroupScheduleVM vm) { try { var list = _attendanceService.GetAll().Result.ToList(); list = AttendanceUtility.FilterByCompanyID(CurrentUser.CompanyID, list); list = AttendanceUtility.FilterByDateFromTo(vm.from, vm.to, list); for (var date = vm.from; date.Date <= vm.to.Date; date = date.AddDays(1)) { if (DayUtility.IsSelected((int)date.DayOfWeek, vm.Week)) { foreach (UsersViewModel user in vm.Users) { if (!AttendanceUtility.IsScheduleAlreadyExist(AttendanceUtility.FilterByUserID(user.ID, list, false), date)) { var model = new Attendance() { ID = Guid.NewGuid().ToString(), UserID = user.ID, AttendanceStatusID = "10", AttendanceDate = date, TimeIn = null, TimeOut = null, ShiftID = vm.shiftID, AddOnID = null, CreatedAt = GetCurrentTime(), CreatedBy = CurrentUser.ID }; _attendanceService.Insert(model); } } } } return(Json(new { success = true })); } catch { return(Json(new { success = false })); } }
public async Task <JsonResult> LoginUser(string Code, string imageUri) { try { var path = Server.MapPath("/UPLOADS/SubscriberFiles/" + CurrentUser.CompanyID); var file = PathChecker.FindAvailableFileName(path, "File"); var users = UsersUtility.FilterByCompany(CurrentUser.CompanyID, _userService.GetAll().Result.ToList()); var user = UsersUtility.FilterByCode(StringFormatter.RemoveStringCharacter(" ", Code), users); if (user.Count > 0) { var attendance = AttendanceUtility.FilterByCompanyID(CurrentUser.CompanyID, _attendanceService.GetAll().Result.ToList()); attendance = AttendanceUtility.FilterByUserID(user.FirstOrDefault().ID, attendance, false); attendance = AttendanceUtility.FilterByDateFromTo(GetCurrentTime(), GetCurrentTime(), attendance); if (attendance.Count > 0) { var attendanceData = new Attendance(); //checks if there is already a timeins if true then timeout that attendance else time in a user var timeout = AttendanceUtility.FilterTimeIn(attendance, false); if (timeout.Count > 0) { if (ImageUpload.UriToServer(imageUri, path + "/" + file)) { attendanceData = timeout.FirstOrDefault(); attendanceData.TimeOutImage = "/UPLOADS/SubscriberFiles/" + CurrentUser.CompanyID + "/" + file; attendanceData.TimeOut = GetCurrentTime().TimeOfDay; attendanceData.UpdatedAt = GetCurrentTime(); } } else { if (ImageUpload.UriToServer(imageUri, path + "/" + file)) { //time in user attendance check if there are timeins already var timeins = AttendanceUtility.FilterTimeIn(attendance, true); attendanceData = timeins.FirstOrDefault(); attendanceData.TimeInImage = "/UPLOADS/SubscriberFiles/" + CurrentUser.CompanyID + "/" + file; attendanceData.TimeIn = GetCurrentTime().TimeOfDay; attendanceData.UpdatedAt = GetCurrentTime(); } } _attendanceService.Update(attendanceData); return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = MessageUtility.TimeOff() })); } } return(Json(new { success = false, message = MessageUtility.UserLoginIDNONExist() })); } catch (Exception e) { return(Json(new { success = false, message = MessageUtility.ServerError(), error = e })); } }
public async Task <JsonResult> GetTimeInToday() { try { var list = AttendanceUtility.FilterByUserID(CurrentUser.ID, _attendanceService.GetAllWithAsync().Result.ToList(), false); var model = AttendanceUtility.FilterByDateFromTo(GetCurrentTime(), GetCurrentTime(), list).FirstOrDefault(); if (model != null) { return(Json(new { success = true, data = AttendanceUtility.MToVM(model) }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = false, data = "" }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(new { success = false, data = e }, JsonRequestBehavior.AllowGet)); } }
public async Task <JsonResult> GetAllUsersTimeInToday() { try { var list = _attendanceService.GetAllWithAsync().Result.ToList(); list = list != null?AttendanceUtility.FilterByCompanyID(CurrentUser.CompanyID, list).ToList() : list; list = AttendanceUtility.FilterByTimeIn(null, list, true); list = AttendanceUtility.FilterByDateFromTo(this.GetCurrentTime(), this.GetCurrentTime(), list).ToList(); list = AttendanceUtility.SortByActualLoginTime(list, false).ToList(); list = AttendanceUtility.SortByActualLogoutTime(list, false); var vms = AttendanceUtility.MsToVMs(list); return(Json(new { success = true, data = vms }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(new { success = false, message = MessageUtility.ServerError(), exception = e }, JsonRequestBehavior.AllowGet)); } }
public async Task <JsonResult> GetByUserIDDate(string id, DateTime fromDate, DateTime toDate) { try { var list = new List <Attendance>(); if (id == null || id == "") { list = AttendanceUtility.FilterByCompanyID(CurrentUser.CompanyID, _attendanceService.GetAllWithAsync().Result.ToList()); } else { list = AttendanceUtility.FilterByUserID(id, _attendanceService.GetAllWithAsync().Result.ToList(), false).ToList(); } list = AttendanceUtility.FilterByIsArchived(list, false); list = AttendanceUtility.FilterByDateFromTo(fromDate, toDate, list).ToList(); list = AttendanceUtility.SortByActualDateTime(list, false); return(Json(new { success = true, data = AttendanceUtility.MsToVMs(list) }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(new { success = false, error = e }, JsonRequestBehavior.AllowGet)); } }