/// <summary> /// Update an admin's info. /// </summary> /// <param name="admin">The administrator with changed values</param> public async Task <Domain.Models.Admins> UpdateAdminAsync(int adminId, Domain.Models.Admins admin) { _logger.LogInformation("Updating administrator with ID {adminId}", adminId); Entities.Admins currentEntity = await _dbContext.Admins.FindAsync(adminId); var newEntity = Mapper.MapAdmins(admin); newEntity.Id = adminId; _dbContext.Entry(currentEntity).CurrentValues.SetValues(newEntity); return(admin); }
/// <summary> /// Add an administrator. /// </summary> /// <param name="admin">The administrator</param> public async Task <Domain.Models.Admins> AddAdminAsync(Domain.Models.Admins admin) { if (admin.Id != 0) { _logger.LogWarning("Administrator to be added has an ID ({adminId}) already: ignoring.", admin.Id); } _logger.LogInformation("Adding administrator"); var entity = Mapper.MapAdmins(admin); entity.Id = 0; await _dbContext.Admins.AddAsync(entity); return(admin); }