예제 #1
0
        public async Task <IActionResult> PutSpecies([FromRoute] string id, [FromBody] Species species)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != species.Name)
            {
                return(BadRequest());
            }

            ctx.Entry(species).State = EntityState.Modified;

            try
            {
                await ctx.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SpeciesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(NoContent());
        }
예제 #2
0
        public async Task <IActionResult> PutUser([FromRoute] string userName, [FromBody] NewUserDTO user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var uti = await _context.User.SingleOrDefaultAsync(m => m.UserName == user.UserName);

            if (uti == null)
            {
                return(NotFound());
            }
            uti.UserName    = user.UserName;
            uti.Email       = user.Email;
            uti.PhoneNumber = user.Phone.ToString();
            await _userManager.RemovePasswordAsync(uti);

            await _userManager.AddPasswordAsync(uti, user.Password);

            _context.Entry(uti).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
            return(NoContent());
        }
예제 #3
0
        public async Task <IActionResult> PutColor([FromRoute] string id, [FromBody] Color color)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ApplicationUser user = await GetCurrentUserAsync();

            var searchRole = ctx.UserRoles.Where(e => e.UserId == user.Id && e.RoleId == "Admin");

            if (searchRole == null)
            {
                return(Unauthorized());
            }

            if (id != color.Name)
            {
                return(BadRequest());
            }

            ctx.Entry(color).State = EntityState.Modified;

            try
            {
                await ctx.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ColorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(NoContent());
        }
예제 #4
0
        public async Task <IActionResult> PutBreed([FromRoute] string id, [FromBody] Breed breed)
        {
            ApplicationUser user = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (await userManager.IsInRoleAsync(user, "Admin"))
            {
                return(Unauthorized());
            }

            if (id != breed.Name)
            {
                return(BadRequest());
            }

            ctx.Entry(breed).State = EntityState.Modified;

            try
            {
                await ctx.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BreedExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(NoContent());
        }