public ActionResult Edit(int id) { var db = new OfferEntities1(); var model = new Offer(); model = db.Offers.Find(id); return(View(model)); }
public ActionResult Delete(int id) { var db = new OfferEntities1(); var model = db.Offers.Find(id); if (model == null) { return(HttpNotFound()); } db.Offers.Remove(model); db.SaveChanges(); return(RedirectToAction("List", "List")); }
public ActionResult Create(Offer newOffer) { OfferEntities1 db = new OfferEntities1(); if (ModelState.IsValid) { db.Offers.Add(newOffer); db.SaveChanges(); return(RedirectToAction("List", "List")); } else { return(View(newOffer)); } }
public ActionResult Edit(Offer list) { var db = new OfferEntities1(); if (ModelState.IsValid) { db.Offers.Add(list); db.Entry(list).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("List", "List")); } return(View(list)); }
// GET: List public ViewResult List(string id, string sortOrder, string searchString, string currentFilter, int?page) { OfferEntities1 db = new OfferEntities1(); ViewBag.CurrentSort = sortOrder; ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; var offers = from o in db.Offers select o; if (!String.IsNullOrEmpty(searchString)) { offers = offers.Where(o => o.Name.Contains(searchString)); } switch (sortOrder) { case "name_desc": offers = offers.OrderByDescending(o => o.Name); break; default: offers = offers.OrderBy(o => o.Name); break; } int pageSize = 5; int pageNumber = (page ?? 1); return(View(offers.ToPagedList(pageNumber, pageSize))); }
public ActionResult Registration(User model) { if (ModelState.IsValid) { using (var db = new OfferEntities1()) { var encryptedPassword = CustomEncrypt.Encrypt(model.Password); var user = db.Users.Create(); user.Email = model.Email; user.Password = encryptedPassword; user.Country = model.Country; user.Name = model.Name; db.Users.Add(user); db.SaveChanges(); } } else { ModelState.AddModelError("", "One or more fields have been"); } return(View()); }