public bool CreateTimeslipsByCustomDay(CustomDateVM customDateVM) { CustomDay_WBIRepo customDay_WBIRepo = new CustomDay_WBIRepo(_context); CustomDayRepo customDayRepo = new CustomDayRepo(_context); var timeslipTemplateList = customDay_WBIRepo.GetAllTimeslipTemplateByCustomDay(customDateVM.CustomdayId); CustomDay customDay = customDayRepo.GetOneCustomDay(customDateVM.CustomdayId); foreach (CustomDay_WBI tt in timeslipTemplateList) { DateTime newStartTime = new DateTime(DateTime.Parse(customDateVM.Date).Year, DateTime.Parse(customDateVM.Date).Month, DateTime.Parse(customDateVM.Date).Day, tt.StartTime.Hour, tt.StartTime.Minute, tt.StartTime.Second); DateTime newEndTime = new DateTime(DateTime.Parse(customDateVM.Date).Year, DateTime.Parse(customDateVM.Date).Month, DateTime.Parse(customDateVM.Date).Day, tt.EndTime.Hour, tt.EndTime.Minute, tt.EndTime.Second); TimeslipVM newTimeslip = new TimeslipVM() { TimeslipId = null, StartTime = Convert.ToString(newStartTime), EndTime = Convert.ToString(newEndTime), Remarks = tt.Remarks, DayId = customDateVM.CustomdayId, WBI_Id = Convert.ToString(tt.NewChangeRequestId), UserId = Convert.ToString(customDay.UserId) }; CreateTimeslip(newTimeslip); } return(true); }
public IActionResult CreateAllTimeslipsFromCustomDay([FromBody] CustomDateVM customDateVM) { //get the custom day (for the user ID) CustomDay customDay = customDayRepo.GetOneCustomDay(customDateVM.CustomdayId); //create a variable to store the date DateTime newDateTime; //check that date given is a valid datetime bool success1 = DateTime.TryParse(customDateVM.Date, out DateTime result1); if (success1) { newDateTime = result1; } else { return(new BadRequestObjectResult(new { message = "Please provide a valid date" })); } //get all the timeslips by user for a single date var userTimeslipsList = timeslipRepo.GetAllTimeslipsByUserIdWithDate(customDay.UserId, newDateTime); //get all timeslip templates by custom day var templateList = customDay_WBIRepo.GetAllTimeslipTemplateByCustomDay(customDateVM.CustomdayId); foreach (var timeslip in userTimeslipsList) { foreach (var template in templateList) { template.StartTime = new DateTime(newDateTime.Year, newDateTime.Month, newDateTime.Day, template.StartTime.Hour, template.StartTime.Minute, template.StartTime.Second); template.EndTime = new DateTime(newDateTime.Year, newDateTime.Month, newDateTime.Day, template.EndTime.Hour, template.EndTime.Minute, template.EndTime.Second); if (template.StartTime < timeslip.NewEndTask && template.EndTime > timeslip.NewStartTask) { return(new BadRequestObjectResult(new { message = "One of the times in this custom day overlaps with an existing timeslip. Your request cannot be processed." })); } } } return(new OkObjectResult(timeslipRepo.CreateTimeslipsByCustomDay(customDateVM))); }