//SaveAsync method public async Task <SaveShiftResponse> SaveAsync(Shift shift) { try { await _shiftRepository.AddAsync(shift); await _unitOfWork.CompleteAsync(); return(new SaveShiftResponse(shift)); } catch (Exception ex) { // Do some logging stuff return(new SaveShiftResponse($"An error occurred when saving the shift: {ex.Message}")); } }
public async Task <ShiftModel> AddAsync(ShiftModel model, int clientId, int userId) { if (!await _permissionManager.HasPermission(clientId, userId, Permission.CanAddShift)) { throw new Exception("User has not permission to perform this operation"); } if (model == null) { throw new ArgumentNullException(); } var shift = _shiftMapper.ConvertToDataModel(model); shift.CreatedOn = DateTime.UtcNow; shift.UpdatedOn = DateTime.UtcNow; shift.CreatedBy = userId; shift.ClientId = clientId; shift.IsActive = true; shift = await _shiftRepository.AddAsync(shift); return(_shiftMapper.ConvertToModel(shift)); }