public async Task <IHttpActionResult> PutInvoice(string id, Invoice invoice) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != invoice.InvoiceId) { return(BadRequest()); } db.Entry(invoice).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InvoiceExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> EditHotel(int id, HotelViewModel hotel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } TestDBEntities db = new TestDBEntities(); var existingHotel = await db.Hotels.Where(h => h.ID == id).SingleOrDefaultAsync(); if (existingHotel == null) { return(BadRequest("Object not found")); } existingHotel.Name = hotel.Name; existingHotel.LastUpdate = DateTime.Now; db.Hotels.Attach(existingHotel); var entry = db.Entry(existingHotel); entry.Property(h => h.Name).IsModified = true; entry.Property(h => h.LastUpdate).IsModified = true; await db.SaveChangesAsync(); return(Ok()); }
public async Task <IHttpActionResult> CreateHotel(HotelViewModel hotel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } TestDBEntities db = new TestDBEntities(); var exist = await db.Hotels .AnyAsync(h => h.Name.Equals(hotel.Name, StringComparison.InvariantCultureIgnoreCase)); if (exist) { return(BadRequest("Object already exist")); } var newHotel = new Hotel { Name = hotel.Name, Date = DateTime.Now, LastUpdate = DateTime.Now }; db.Hotels.Add(newHotel); await db.SaveChangesAsync(); var location = Request.RequestUri + newHotel.ID.ToString(); return(Created(location, newHotel)); }
public async Task <ActionResult> Create([Bind(Include = "ProdId,ProdNombre,CatId,Precio,ProdObservacion")] tblProduct tblProduct) { try { if (ModelState.IsValid) { db.tblProduct.Add(tblProduct); await db.SaveChangesAsync(); Success(string.Format("<b>{0}</b> fue exitosamente agregado.", tblProduct.ProdNombre), true); return(RedirectToAction("Index")); } ViewBag.CatId = new SelectList(db.tblProductCategory, "CatId", "CatNombre", tblProduct.CatId); return(View(tblProduct)); } catch (Exception) { throw; } }
public async Task <IHttpActionResult> Post(ReviewItem item) { using (TestDBEntities db = new TestDBEntities()) { Reviews rec = new Reviews() { ClientName = item.ClientName, Review = item.Review }; db.Reviews.Add(rec); await db.SaveChangesAsync(); item.ID = rec.ID; return(Ok(item)); } }
public async Task <IHttpActionResult> DeleteHotel(int id) { TestDBEntities db = new TestDBEntities(); var hotel = await db.Hotels.Where(h => h.ID == id).SingleOrDefaultAsync(); if (hotel == null) { return(BadRequest("Object not found")); } db.Hotels.Remove(hotel); await db.SaveChangesAsync(); return(Ok()); }