public void Add(List<AttentdenceRequest> requests) { var trans = UnitOfWork.CreateTransac(); try { foreach (var item in requests) { var emp = employeeService.FindById(item.EmployeeId); if (emp == null) { throw ApiException.Get(false, ConstantManager.NotFound("Employee "), ResultEnum.EmpNotFound, HttpStatusCode.NotFound); } var entity = Mapper.Map<AttentdenceRequest, Attendance>(item); //item.ToEntity(); for (int i = 0; i < item.Dates.Count; i++) { entity.ShiftMax = item.Dates[i].GetStartOfDate().Add(item.ShiftMaxTime[i]); entity.ShiftMin = item.Dates[i].GetStartOfDate().Add(item.ShiftMaxTime[i]); entity.ExpandTime = new TimeSpan(); entity.CheckInExpandTime = new TimeSpan(1, 0, 0); entity.CheckOutExpandTime = new TimeSpan(1, 0, 0); entity.ComeLateExpandTime = new TimeSpan(1, 0, 0); entity.LeaveEarlyExpandTime = new TimeSpan(1, 0, 0); entity.ProcessingStatus = (int)ProcessingStatusAttendenceEnum.Assign; var timeFrameId = item.TimeFramId[i]; var tf = timeFrameService.FindById(timeFrameId); if (tf == null) { throw ApiException.Get(false, ConstantManager.NotFound("Time Frame "), ResultEnum.TimeFrameNotFound, HttpStatusCode.NotFound); } entity.TimeFramId = tf.Id; entity.Active = true; entity.Status = (int)StatusAttendanceEnum.Processing; Create(entity); } } trans.Commit(); } catch (Exception e) { trans.Dispose(); if (e is ApiException) { throw e; } else { ApiException.Get(false, ConstantManager.FAIL, ResultEnum.InternalError, HttpStatusCode.InternalServerError); } } }
public List <ShiftRegisterResponse> Get() { var result = GetAsNoTracking(p => p.Active == true) .Select(a => new ShiftRegisterResponse(a, mapper) { EmpName = a.Employee.Name, StartTimeVM = /*new TimeSpan(a.StartTime.Hour, a.StartTime.Minute, 0)*/ a.StartTime.TimeOfDay, EndTimeVM = /*new TimeSpan(a.EndTime.Hour, a.EndTime.Minute, 0)*/ a.EndTime.TimeOfDay, StartDate = a.StartTime.Date, EndDate = a.EndTime.Date, StatusName = ((ShiftRegisterEnum)a.Status).DisplayName() }).ToList(); foreach (var item in result) { item.TimeFrameName = timeFrameService.FindById(item.TimeframeId).Name; } return(result); }