예제 #1
0
        public async Task <IActionResult> PutContact([FromRoute] int id, [FromBody] Contact contact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != contact.Id ||
                _userManager.GetUserId(User) != contact.UserId)
            {
                return(BadRequest());
            }

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

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

                throw;
            }

            return(new StatusCodeResult(StatusCodes.Status204NoContent));
        }
        public async Task <IActionResult> PutContact([FromRoute] int id, [FromBody] Contact contact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
예제 #3
0
 public void Detach(T entity)
 {
     if (entity != null)
     {
         _context.Entry(entity).State = EntityState.Detached;
     }
 }
예제 #4
0
        public async Task <IActionResult> PutMyContacts(string id, Contacts contact)
        {
            if (id != contact.ContactId)
            {
                return(BadRequest());
            }

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

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

            return(Ok());
        }
예제 #5
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,name,Phone,Email,DateOfBirth")] Contact contact)
        {
            if (ModelState.IsValid)
            {
                db.Entry(contact).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(contact));
        }
예제 #6
0
        public bool UpdateContact(Person person)
        {
            if (person == null)
            {
                return(false);
            }

            _context.Entry(person).State = EntityState.Modified;
            _context.SaveChanges();

            return(true);
        }
예제 #7
0
        public IActionResult Put(string id, Users user)
        {
            if (id != user.Id)
            {
                return(BadRequest("Id's do not match!"));
            }

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

            try
            {
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
            return(Ok());
        }
예제 #8
0
 public void Update(Contact contact)
 {
     _ctx.Entry(contact).State = EntityState.Modified;
     _ctx.SaveChanges();
 }