public async Task <UserForUpdateDto> RemoveCredit(int id, UserForUpdateDto user) { var dbUser = await _context.Users .FirstOrDefaultAsync(x => x.Id == id); dbUser.Credit = dbUser.Credit - user.Credit; await _context.SaveChangesAsync(); return(UserTranslator.ToUserForUpdateDto(dbUser)); }
public async Task <UserForUpdateDto> UpdateOffice(int id, string newOffice) { var dbUser = await _context.Users.Include(u => u.Office) .FirstOrDefaultAsync(x => x.Id == id); var dbOffice = await _context.Offices.FirstOrDefaultAsync(x => x.Name == newOffice); dbUser.OfficeId = dbOffice.Id; await _context.SaveChangesAsync(); return(UserTranslator.ToUserForUpdateDto(dbUser)); }
public async Task <UserForUpdateDto> AddCredit(int id, int amount) { var dbUser = await _context.Users .FirstOrDefaultAsync(x => x.Id == id); if (amount > 0) { dbUser.Credit = dbUser.Credit + amount; await _context.SaveChangesAsync(); } if (amount < 0) { dbUser.Credit = dbUser.Credit + amount; await _context.SaveChangesAsync(); } return(UserTranslator.ToUserForUpdateDto(dbUser)); }
public async Task <UserForUpdateDto> UpdateAdminStatus(int id, string status) { var dbUser = await _context.Users .FirstOrDefaultAsync(x => x.Id == id); if (status == "true") { dbUser.Admin = true; } else { dbUser.Admin = false; } await _context.SaveChangesAsync(); return(UserTranslator.ToUserForUpdateDto(dbUser)); }