Esempio n. 1
0
        public async Task <UserInfoDTO> EditUser(EditUserDTO editUserDTO)
        {
            var user = await _context.Users.AsNoTracking().FirstOrDefaultAsync(x => x.Id == editUserDTO.Id);

            try
            {
                if (user != null)
                {
                    user.FirstName   = editUserDTO.FirstName;
                    user.MiddleName  = editUserDTO.MiddleName;
                    user.LastName    = editUserDTO.LastName;
                    user.Address     = editUserDTO.Address;
                    user.PhoneNumber = editUserDTO.PhoneNumber;


                    _context.Users.Update(user);
                    _context.SaveChanges();
                    return(_mapper.Map <UserInfoDTO>(user));
                }
                throw new NullReferenceException();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Esempio n. 2
0
        public async Task <Guid> MarkAsAvailable(Guid id)
        {
            try
            {
                var vehicle = await _context.Vehicles.FirstOrDefaultAsync(x => x.ID == id);

                if (vehicle != null)
                {
                    vehicle.UpdateAvailability();
                    vehicle.RentalEvents.Select(x => x.IsActive = false);
                }
                _context.SaveChanges();
                return(vehicle.ID);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }