Esempio n. 1
0
        public async Task <IActionResult> PutUser(int Id, User user)
        {
            if (!userRepository.isUserAdmin(GetUserId()))
            {
                return(BadRequest(new { isAdmin = "User does not have Admin priviledges!" }));
            }

            user.Id = Id;

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> PutCar(int Id, Car car)
        {
            car.Id = Id;

            _context.Entry(car).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CarExists(Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public virtual void Add(T entity)
        {
            EntityEntry dbEntityEntry = _context.Entry <T>(entity);

            _context.Set <T>().Add(entity);
        }