Пример #1
0
        public async Task <IHttpActionResult> PutContact(int id, Contact contact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult Edit([Bind(Include = "PhoneNumberID,PhoneNumberNumber,PhoneNumberType,ContactID")] PhoneNumber phoneNumber)
        {
            if (ModelState.IsValid)
            {
                db.Entry(phoneNumber).State = EntityState.Modified;
                db.SaveChanges();
                return(Content("PhoneNumber updated"));
            }
            var errors = ModelState.Select(x => x.Value.Errors)
                         .Where(y => y.Count > 0)
                         .ToList();

            return(Json(errors));
        }
Пример #3
0
        public ActionResult Edit([Bind(Include = "ContactID,ContactFirstName,ContactLastName,ContactAddress,ContactEmail,ContactDefaultNumber,ContactDefaultNumberType")] Contact contact)
        {
            if (ModelState.IsValid)
            {
                db.Entry(contact).State = EntityState.Modified;
                db.SaveChanges();
                return(Content("Contact Updated"));
            }
            var errors = ModelState.Select(x => x.Value.Errors)
                         .Where(y => y.Count > 0)
                         .ToList();

            return(Json(errors));
        }
Пример #4
0
 /// <summary>
 /// Update Contacts.
 /// </summary>
 /// <param name="student"></param>
 public void UpdateContact(Contact student)
 {
     _context.Entry(student).State = EntityState.Modified;
 }