public async Task <ActionResult <VacationPackage> > PostVacationPackage(VacationPackage vacationPackage) { _context.VacationPackages.Add(vacationPackage); await _context.SaveChangesAsync(); return(CreatedAtAction("GetVacationPackage", new { id = vacationPackage.Id }, vacationPackage)); }
public async Task <IActionResult> PutVacationPackage(int id, VacationPackage vacationPackage) { if (id != vacationPackage.Id) { return(BadRequest()); } _context.Entry(vacationPackage).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VacationPackageExists(id)) { return(NotFound()); } throw; } return(NoContent()); }
public ActionResult DeleteConfirmed(int id) { //get the currect VacationPackage by id and remove him from db, finally retrun to index page VacationPackage vacationpackage = db.VacationPackages.Find(id); db.VacationPackages.Remove(vacationpackage); db.SaveChanges(); return(RedirectToAction("Index")); }
/*Details method-get vacationPackage id and return his data */ // GET: /VacationPackage/Details/5 public ActionResult Details(int id = 0) { //get from db.VacationPackage the currect vacation-Package by id VacationPackage vacationpackage = db.VacationPackages.Find(id); if (vacationpackage == null) { return(HttpNotFound()); } return(View(vacationpackage)); }
/*Edit GET method-get VacationPackage id */ // GET: /VacationPackage/Edit/5 public ActionResult Edit(int id = 0) { //get the currect vacationpackage by id VacationPackage vacationpackage = db.VacationPackages.Find(id); //check if vacationpackage is null if (vacationpackage == null) { return(HttpNotFound()); } ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", vacationpackage.SupplierID); return(View(vacationpackage)); }
/*Delete GET method-get VacationPackage id */ // GET: /VacationPackage/Delete/5 public ActionResult Delete(int?id) { //check if VacationPackage id is null if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //if VacationPackage's id is not null -get the currect VacationPackage by id VacationPackage vacationpackage = db.VacationPackages.Find(id); //check if get null if (vacationpackage == null) { return(HttpNotFound()); } return(View(vacationpackage)); }
public bool CeateVacationPackage(VacationPackageCreate vacpac) { var entity = new VacationPackage() { OwnerId = _userId, Price = vacpac.Price, Transportation = vacpac.Transportation, VacationPackageName = vacpac.VacPacName, Flight = vacpac.Flight, Food = vacpac.Food, HotelId = vacpac.HotelId, }; using (var ctx = new ApplicationDbContext()) { ctx.VacationPackage.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(VacationPackage vacationpackage, HttpPostedFileBase file) { //check if VacationPackage object is valid and then save the change in db.VacationPackage, finally return to the same page with object after change if (ModelState.IsValid) { db.Entry(vacationpackage).State = EntityState.Modified; //check if file is not null-save change and return to Index page if (file != null) { //save upload image in project and his name in db file.SaveAs(HttpContext.Server.MapPath("~/img/") + file.FileName); vacationpackage.Image = file.FileName; } db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", vacationpackage.SupplierID); return(View(vacationpackage)); }
public ActionResult Create(VacationPackage vacationpackage, HttpPostedFileBase file) { //check if VacationPackage object is valid and then add him to db.Suppliers, finally return to supplier Index page if (ModelState.IsValid) { //check if file is not null if (file != null) { //save upload image in project and his name in db file.SaveAs(HttpContext.Server.MapPath("~/img/") + file.FileName); vacationpackage.Image = file.FileName; } //add package to db.VacationPackage and return to Index page db.VacationPackages.Add(vacationpackage); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", vacationpackage.SupplierID); return(View(vacationpackage)); }