public async Task <IActionResult> PutPhone(int id, Phone phone) { if (id != phone.PhoneId) { return(BadRequest()); } _context.Entry(phone).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PhoneExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IHttpActionResult PutPhone(int id, Phone phone) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != phone.Id) { return(BadRequest()); } db.Entry(phone).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PhoneExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
[HttpPut]//http://localhost:22146/api/ApiPhoneModels/Add?Phone=333&Surname=aaaaa&Firstname=aaaaaa&Middlename=middle&BDay=07.01.2017 public IHttpActionResult Put(string phone, string Surname, string Firstname, string Middlename, DateTime BDay) { PhoneModel phoneModel = db.PhoneModels.Find(phone); if (phoneModel == null) { return(BadRequest("NotFound")); } phoneModel.Surname = Surname; phoneModel.Firstname = Firstname; phoneModel.Middlename = Middlename; phoneModel.BDay = BDay; db.Entry(phoneModel).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (db.PhoneModels.Count(e => e.Phone == phone) < 0) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutAddress(int id, Address address) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != address.ID) { return(BadRequest()); } db.Entry(address).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AddressExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public static void AddUpdatePhoneBookDetails(PhoneDetails phoneDetails) { try { var context = new PhoneContext(); if (phoneDetails.PhoneBookId == 0) { context.dbPhoneDetails.Add(phoneDetails); context.SaveChanges(); } else { var result = context.dbPhoneDetails.Find(phoneDetails.PhoneBookId); if (result != null) { context.Entry(result).CurrentValues.SetValues(phoneDetails); context.SaveChanges(); } } } catch (Exception ex) { throw ex; } }
public ActionResult EditPhone(Phone objbook) { int StudentId = (int)TempData["StudentId"]; var StudentData = this.pdb.Phones.Where(b => b.Id == StudentId).FirstOrDefault(); if (StudentData != null) { StudentData.Name = objbook.Name; StudentData.Surname = objbook.Surname; StudentData.Number = objbook.Number; StudentData.Email = objbook.Email; StudentData.GId = objbook.GId; StudentData.UId = objbook.UId; pdb.Entry(StudentData).State = EntityState.Modified; this.pdb.SaveChanges(); } return(RedirectToAction("Phone")); }
public ActionResult Edit([Bind(Include = "Id,SurName,FirstName,MiddleName,DateOfBirth,Number")] Phone phone) { if (ModelState.IsValid) { db.Entry(phone).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Browse")); } return(View(phone)); }
public async Task <IActionResult> PutPhone(int id, Phone phone) { if (id != phone.Id) { return(BadRequest()); } _context.Entry(phone).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); }
public ActionResult Update(Phone phone) { if (ModelState.IsValid) { Phones.Entry(phone).State = EntityState.Modified; Phones.SaveChanges(); return(View("Index", Phones.Phones)); } else { ViewBag.ErrorTxt = "Update: error"; return(View("Index", Phones.Phones)); } }
public ActionResult EditGroup(Group objgroup) { int StudentId = (int)TempData["StudentId"]; var StudentData = this.pdb.Groups.Where(b => b.GId == StudentId).FirstOrDefault(); if (StudentData != null) { StudentData.Name = objgroup.Name; StudentData.UId = objgroup.UId; pdb.Entry(StudentData).State = EntityState.Modified; this.pdb.SaveChanges(); } return(RedirectToAction("Admin")); }
public static void DeletePhoneBookDetailsById(int phoneBookId) { try { var context = new PhoneContext(); PhoneDetails detail = new PhoneDetails { PhoneBookId = phoneBookId }; context.Entry(detail).State = EntityState.Deleted; context.SaveChanges(); } catch (Exception ex) { throw ex; } }
public void ProcessRequest(HttpContext context) { if (context.Request.HttpMethod == "GET") { List <Phone> phones = db.Phones.ToList(); string json = JsonSerializer.Serialize <List <Phone> >(phones); string result = json; context.Response.ContentType = "text/json"; context.Response.StatusCode = 200; context.Response.Write(result); } if (context.Request.HttpMethod == "POST") { var reader = new StreamReader(context.Request.InputStream); var inputString = reader.ReadToEnd(); Phone newPhone = JsonSerializer.Deserialize <Phone>(inputString); db.Phones.Add(newPhone); db.SaveChanges(); } if (context.Request.HttpMethod == "PUT") { var reader = new StreamReader(context.Request.InputStream); var inputString = reader.ReadToEnd(); Phone newPhone = JsonSerializer.Deserialize <Phone>(inputString); var phone = db.Phones.FirstOrDefault(t => t.Id == newPhone.Id); phone.Last_name = newPhone.Last_name; phone.Phone_number = newPhone.Phone_number; db.SaveChanges(); } if (context.Request.HttpMethod == "DELETE") { var reader = new StreamReader(context.Request.InputStream); var inputString = reader.ReadToEnd(); Phone deletePhone = JsonSerializer.Deserialize <Phone>(inputString); db.Entry(deletePhone).State = EntityState.Deleted; db.SaveChanges(); } }
public IHttpActionResult Put(Phone ToUpdatePhone) { Phone phone = context.Phones.Find(ToUpdatePhone.ID); phone.Surname = ToUpdatePhone.Surname; phone.FirstName = ToUpdatePhone.FirstName; phone.MiddleName = ToUpdatePhone.MiddleName; phone.PhoneNumber = ToUpdatePhone.PhoneNumber; phone.BDay = ToUpdatePhone.BDay; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (ToUpdatePhone.ID != phone.ID) { return(BadRequest()); } context.Entry(phone).State = System.Data.Entity.EntityState.Modified; try { context.SaveChanges(); return(Ok(phone)); } catch (DbUpdateConcurrencyException) { if (!PhoneExists(ToUpdatePhone.ID)) { return(NotFound()); } else { throw; return(StatusCode(HttpStatusCode.NoContent)); } } }