public async Task <IActionResult> GetAllCalendarsByWorkTimeJsonForKendo([DataSourceRequest] DataSourceRequest request , ContractWorkTime contractWorkTime) { var manager = _dataManager as WorkCalendarsManager; var resultDataList = await manager.GetAllAsNoTrackingListAsync(w => w.ContractWorkTime == contractWorkTime); var resultDataModelList = await mapToViewModelsDataCollection(resultDataList); resultDataModelList = await fillMissingItemsData(resultDataModelList); return(Json(resultDataModelList.ToDataSourceResult(request))); }
public async Task <List <CalendarDayReport> > GetCalendarsDaysReport(ContractWorkTime workTime, DateTime?fromDate = null, DateTime?toDate = null) { try { fromDate = fromDate ?? new DateTime(2018, 12, 1); toDate = toDate ?? DateTime.Today; var results = new List <CalendarDayReport>(); DateTime startDate = fromDate.Value; while (startDate <= toDate) { bool dayOff = startDate.DayOfWeek == DayOfWeek.Friday || startDate.DayOfWeek == DayOfWeek.Saturday; results.Add(new CalendarDayReport { DayDate = startDate, IsDayOff = dayOff, DayOffDescription = dayOff ? "نهاية الاسبوع" : "", CheckInDateTime = !dayOff ? startDate.Date.Add(new TimeSpan(7, 30, 0)) : default(DateTime?), CheckOutDateTime = !dayOff ? startDate.Date.Add(new TimeSpan(14, 30, 0)) : default(DateTime?), WorkDuration = !dayOff ? new TimeSpan(7, 30, 0) : default(TimeSpan?) }); startDate = startDate.AddDays(1); } var workTimeCalenars = await GetAllAsNoTrackingListAsync(c => c.ContractWorkTime == workTime && (!c.EndDate.HasValue && c.StartDate <= toDate.Value) || (c.EndDate.HasValue && c.EndDate >= fromDate.Value && c.StartDate <= toDate.Value), c => c.WorkShifts); foreach (var calendar in workTimeCalenars.Where(c => !c.EndDate.HasValue).OrderBy(c => c.StartDate)) { var calendarDaysReports = calendar.GetDaysReports(fromDate, toDate); results.RemoveAll(d => calendarDaysReports.Any(cd => cd.DayDate.Date == d.DayDate.Date)); results.AddRange(calendarDaysReports); } foreach (var calendar in workTimeCalenars.Where(c => c.EndDate.HasValue).OrderBy(c => c.StartDate)) { var calendarDaysReports = calendar.GetDaysReports(fromDate, toDate); results.RemoveAll(d => calendarDaysReports.Any(cd => cd.DayDate.Date == d.DayDate.Date)); results.AddRange(calendarDaysReports); } return(results.OrderBy(d => d.DayDate).ToList()); } catch (Exception) { throw; } }
public static string GetText(this ContractWorkTime contractWorkTime) { switch (contractWorkTime) { case ContractWorkTime.ShiftA: return("المجموعة أ"); case ContractWorkTime.ShiftB: return("المجموعة ب"); case ContractWorkTime.ShiftC: return("المجموعة ج"); case ContractWorkTime.ShiftD: return("المجموعة د"); case ContractWorkTime.ShiftH: return("المجموعة هـ"); default: return("موظفي الصباح"); } }
public async Task <IActionResult> GetCalendarsDaysForKendo([DataSourceRequest] DataSourceRequest request, ContractWorkTime workTime , DateTime?fromDate = null, DateTime?toDate = null) { try { var manager = _dataManager as WorkCalendarsManager; var results = await manager.GetCalendarsDaysReport(workTime, fromDate, toDate); return(Json(_mapper.Map <List <CalendarDayReportViewModel> >(results).ToDataSourceResult(request))); } catch (ValidationException ex) { return(Json(new { errors = new string[] { ex.ValidationResult.ErrorMessage } })); } catch (System.Exception) { return(Json(new { errors = new string[] { "خطأ أثناء قراءة البيانات الرجاء المحاولة لاحقاً" } })); } }
public async Task <IActionResult> AddOrUpdateEmployeeCalendar(int employeeId, int calendarId, bool isOpenCalendar, DateTime startDate, DateTime endDate, ContractWorkTime workTime, AttendanceProof attendanceProof, string note) { try { var newData = new EmployeeCalendar { Id = calendarId, StartDate = startDate, EndDate = isOpenCalendar? default(DateTime?) : endDate, ContractWorkTime = workTime, AttendanceProof = attendanceProof, EmployeeId = employeeId, Note = note, }; if (User.Identity.IsAuthenticated) { newData.UserId = User.Identity.Name.ConvertToInteger(); } if (newData.Id == 0) { var saveResult = await _employeesCalendarsManager.InsertNewAsync(newData); if (saveResult.Status == RepositoryActionStatus.Created) { return(Json("ok")); } else { return(Json(new { errors = "Error" })); } } else { var currentData = await _employeesCalendarsManager.GetByIdAsync(newData.Id); if (currentData == null) { return(Json(new { errors = "NotFound" })); } currentData.StartDate = newData.StartDate; currentData.EndDate = newData.EndDate; currentData.ContractWorkTime = newData.ContractWorkTime; currentData.AttendanceProof = newData.AttendanceProof; currentData.Note = newData.Note; currentData.UserId = newData.UserId; var updateResult = await _employeesCalendarsManager.UpdateDataItem(currentData); if (updateResult.Status == RepositoryActionStatus.Updated) { return(Json("ok")); } else { return(Json(new { errors = "Error" })); } } } catch (Exception ex) { if (!string.IsNullOrWhiteSpace(ex.Message)) { if (ex.Message.Contains("before")) { return(Json(new { errors = "enddate" })); } } return(Json(new { errors = "Error" })); } }