public async Task <IActionResult> Create(ShiftCalendarEditViewModel viewModel) { if (!ModelState.IsValid) { return(View()); } var dateExists = await _shiftCalendarService.ExistsAsync(viewModel.WorkDate); if (dateExists) { ModelState.AddModelError("Error", "Work date already exists."); return(View(viewModel)); } var shift = new ShiftCalendarModel { WorkDate = viewModel.WorkDate, WorkType = viewModel.WorkType, ShiftId = viewModel.ShiftId }; await _shiftCalendarService.AddAsync(shift); return(RedirectToAction(nameof(Index))); }
public async Task UpdateAsync(ShiftCalendarModel model) { var calendar = await _repository.GetSingleAsync(x => x.WorkDate == model.WorkDate); calendar.WorkType = model.WorkType; calendar.ShiftId = model.ShiftId; await _repository.UpdateAsync(calendar); }
public async Task AddAsync(ShiftCalendarModel model) { var shiftCalendar = new MasterShiftCalendar { WorkDate = model.WorkDate, WorkType = model.WorkType, ShiftId = model.ShiftId }; await _repository.AddAsync(shiftCalendar); }
public async Task <IActionResult> Edit(ShiftCalendarEditViewModel model) { if (!ModelState.IsValid) { return(View()); } var shift = new ShiftCalendarModel { WorkDate = model.WorkDate, WorkType = model.WorkType, ShiftId = model.ShiftId }; await _shiftCalendarService.UpdateAsync(shift); return(RedirectToAction(nameof(Index))); }