コード例 #1
0
        public async Task <IActionResult> Put([FromRoute] int id, [FromBody] BuyingPower buyingPower)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != buyingPower.Id)
            {
                return(BadRequest());
            }

            buyingPower.ModifiedUserId = Convert.ToInt32(((ClaimsIdentity)HttpContext.User.Identity).FindFirst(ClaimTypes.Sid).Value);
            buyingPower.ModifiedDate   = DateTime.Now;

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

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

            return(Ok(buyingPower));
        }
コード例 #2
0
        public async Task <IActionResult> Post([FromBody] BuyingPower buyingPower)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var x = HttpContext.User.Identity.Name;

            buyingPower.ModifiedUserId = Convert.ToInt32(((ClaimsIdentity)HttpContext.User.Identity).FindFirst(ClaimTypes.Sid).Value);
            buyingPower.ModifiedDate   = DateTime.Now;

            _context.BuyingPower.Add(buyingPower);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("Get", new { id = buyingPower.Id }, buyingPower));
        }