Пример #1
0
        public async Task <IActionResult> PutUserModel([FromRoute] int id, [FromBody] UserModel userModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userModel.UserId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> PutMembership([FromRoute] int id, [FromBody] Membership membership)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != membership.MembershipId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #3
0
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="model">实体对象</param>
 /// <returns></returns>
 public async Task <int> AddAsync(T model)
 {
     _db.Entry(model).State = EntityState.Added;
     return(await _db.SaveChangesAsync());
 }