Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        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));
        }