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

            nguontiepnhan.NgayNhap  = DateTime.Now;
            nguontiepnhan.NguoiNhap = user;
            _context.NguonTiepNhans.Add(nguontiepnhan);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetNguonTiepNhan", new { id = nguontiepnhan.NguonTiepNhanId }, nguontiepnhan));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutNguonTiepNhan([FromRoute] int id, [FromBody] NguonTiepNhan nguontiepnhan)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }