public async Task OnDeleteWorkShift() { List <WorkShift_Dto> workshifts = JsonSerializer.Deserialize <List <WorkShift_Dto> >(Request.Form["workshifts"]); for (int i = 0; i < workshifts.Count; i++) { WorkShift_Dto workshift = workshifts[i]; await WorkShiftsAppService.DeleteAsync(workshift.Id); } }
public async Task <IActionResult> OnPost() { if (ModelState.IsValid) { try { var formData = Request.Form; WorkShiftViewModel generalInfo = new WorkShiftViewModel(); generalInfo = JsonSerializer.Deserialize <WorkShiftViewModel>(formData["info"].ToString()); generalInfo.initialize(); if (generalInfo.IsEditing) { WorkShift workShift = WorkShiftsAppService.Repository.First(x => x.Id == generalInfo.Id); workShift.Title = generalInfo.Title; workShift.DepartmentId = generalInfo.DepartmentId; workShift.StartHour = generalInfo.StartHour; workShift.EndHour = generalInfo.EndHour; WorkShift workShiftAdded = await WorkShiftsAppService.Repository.UpdateAsync(workShift); WorkShift_Dto workShiftDto = ObjectMapper.Map <WorkShift, WorkShift_Dto>(WorkShiftsAppService.Repository.WithDetails(x => x.Department).First(x => x.Id == workShiftAdded.Id)); return(new JsonResult(workShiftDto)); } else { WorkShift_Dto workShift = new WorkShift_Dto(); workShift.Title = generalInfo.Title; workShift.DepartmentId = generalInfo.DepartmentId; workShift.StartHour = generalInfo.StartHour; workShift.EndHour = generalInfo.EndHour; WorkShift_Dto workShiftAdded = await WorkShiftsAppService.CreateAsync(workShift); WorkShift_Dto workShiftDto = ObjectMapper.Map <WorkShift, WorkShift_Dto>(WorkShiftsAppService.Repository.WithDetails(x => x.Department).First(x => x.Id == workShiftAdded.Id)); return(new JsonResult(workShiftDto)); } } catch (Exception ex) { return(StatusCode(500)); } } return(NoContent()); }