public async Task <Result> DeleteAsync(Guid employeeId) { EmployeeEntity?employeeEntity = await dbContext.Employees.FindAsync(employeeId); if (employeeEntity == null) { return(Result.Fail(new EmployeeNotExistsError())); } dbContext.Employees.Remove(employeeEntity); await dbContext.SaveChangesAsync(); return(Result.Ok()); }
public async Task <Result> SaveAsync(Guid employeeId, WorkEvent workEvent) { if (await EmployeeNotExists(employeeId)) { return(Result.Fail(new EmployeeNotExistsError())); } if (await EmployeeAddedWorkEventAtTime(employeeId, workEvent.DateTimeInstant)) { return(Result.Fail(new WorkEventAlreadyExistsError($"Employee: {employeeId} already have event with the same date time instant: {workEvent.DateTimeInstant}"))); } await dbContext.WorkEvents.AddAsync(new WorkEventEntity { EmployeeId = employeeId, DateTimeInstant = workEvent.DateTimeInstant.ToUniversalTime() }); await dbContext.SaveChangesAsync(); return(Result.Ok()); }