Ejemplo n.º 1
0
        public async Task <IActionResult> PutSkinTones(ulong id, [FromBody] SkinTones skinTones)
        {
            if (!_authorizationService.ValidateJWTCookie(Request))
            {
                return(Unauthorized(new { errors = new { Token = new string[] { "Invalid token" } }, status = 401 }));
            }

            if (id != skinTones.Id)
            {
                return(BadRequest(new { errors = new { Id = new string[] { "ID sent does not match the one in the endpoint" } }, status = 400 }));
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <SkinTones> > PostSkinTones([FromBody] SkinTones skinTones)
        {
            if (!_authorizationService.ValidateJWTCookie(Request))
            {
                return(Unauthorized(new { errors = new { Token = new string[] { "Invalid token" } }, status = 401 }));
            }

            if (skinTones.Id != null)
            {
                skinTones.Id = null;
            }

            _context.SkinTones.Add(skinTones);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetSkinTones", new { id = skinTones.Id }, skinTones));
        }