Example #1
0
        public async Task <IActionResult> PostLoaiGiaThue([FromBody] LoaiGiaThue loaigiathue)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var user   = User.Identity.Name;
            var userId = Utilities.GetUserId(this.User);

            loaigiathue.NgayNhap  = DateTime.Now;
            loaigiathue.NguoiNhap = user;
            _context.LoaiGiaThues.Add(loaigiathue);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetLoaiGiaThue", new { id = loaigiathue.LoaiGiaThueId }, loaigiathue));
        }
Example #2
0
        public async Task <IActionResult> PutLoaiGiaThue([FromRoute] int id, [FromBody] LoaiGiaThue loaigiathue)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }