Exemplo n.º 1
0
        public async Task <IActionResult> PostTrangThaiYeuCau([FromBody] TrangThaiYeuCau trangthaiyeucau)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var user   = User.Identity.Name;
            var userId = Utilities.GetUserId(this.User);

            trangthaiyeucau.NgayNhap  = DateTime.Now;
            trangthaiyeucau.NguoiNhap = user;
            _context.TrangThaiYeuCaus.Add(trangthaiyeucau);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTrangThaiYeuCau", new { id = trangthaiyeucau.TrangThaiYeuCauId }, trangthaiyeucau));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutTrangThaiYeuCau([FromRoute] int id, [FromBody] TrangThaiYeuCau trangthaiyeucau)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != trangthaiyeucau.TrangThaiYeuCauId)
            {
                return(BadRequest());
            }
            var user   = User.Identity.Name;
            var userId = Utilities.GetUserId(this.User);

            trangthaiyeucau.NgaySua  = DateTime.Now;
            trangthaiyeucau.NguoiSua = user;
            _context.Entry(trangthaiyeucau).State = EntityState.Modified;

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

            return(NoContent());
        }