public IHttpActionResult PutCustomer(short id, Customer customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != customer.CustomerID) { return(BadRequest()); } db.Entry(customer).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Put(CustomerViewModel customer) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } using (var ctx = new CustomerConnection()) { var existingCustomer = ctx.Customers.Where(s => s.CustomerId == customer.CostumerId) .FirstOrDefault <Customer>(); if (existingCustomer != null) { existingCustomer.Name = customer.Name; existingCustomer.EmailId = customer.EmailId; existingCustomer.Address = customer.Address; existingCustomer.MobileNo = customer.MobileNo; ctx.SaveChanges(); } else { return(NotFound()); } } return(Ok()); }
public IHttpActionResult Post() { using (var ctx = new CustomerConnection()) { ctx.Customers.Add(new Customer() { Name = "Eduardo", Address = "Rua Das Margaridas", EmailId = "@google.com", MobileNo = "1199993333", Birthday = DateTime.Now }); ctx.SaveChanges(); } return(Ok()); }
public IHttpActionResult Delete(int id) { if (id <= 0) { return(BadRequest("Not a valid student id")); } using (var ctx = new CustomerConnection()) { var customer = ctx.Customers .Where(s => s.CustomerId == id) .FirstOrDefault(); ctx.Entry(customer).State = System.Data.Entity.EntityState.Deleted; ctx.SaveChanges(); } return(Ok()); }