public IActionResult GetOneCustomDay(string id) { if (id == null || id == "") { return(new BadRequestObjectResult(new { message = "Please provide a valid custom day id" })); } return(new OkObjectResult(customDayRepo.GetOneCustomDay(id))); }
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))); }