public async Task <int> DeleteAsync(int id) { var timesheet = await _timesheetRepository.FirstOrDefaultAsync(x => x.Id == id, x => x.Include(y => y.Employee)); if (timesheet == null) { throw new ValidationException($"Error : TimesheetId {id} does not exist"); } if (!timesheet.Employee.SystemUserId.Equals(_currentUserService.UserId)) { var currentUser = await _userManager.FindByIdAsync(_currentUserService.UserId); if (!await _userManager.IsInRoleAsync(currentUser, RoleConstant.AdministratorRole)) { throw new ValidationException($"Error : Dont have permissions to do it."); } } _timesheetRepository.Remove(timesheet); return(await _unitOfWork.SaveChangesAsync()); }
public void Remove(int id) { var timesheet = this.Get(id); _timesheetRepository.Remove(id); }
public void Remove(Timesheet Timesheet) { _timesheetRepo.Remove(Timesheet); }