public ActionResult Save(Category category) { if (ModelState.IsValid) { using (AradaLejDBContext _context = new AradaLejDBContext()) { if (category.Id > 0) { //edit var c = _context.Category.Where(a => a.Id == category.Id).FirstOrDefault(); if (c != null) { c.CategoryImage = category.CategoryImage; c.Name = category.Name; c.Status = category.Status; } } else { _context.Category.Add(category); } _context.SaveChanges(); } return(RedirectToAction("ManageCategory", "Category")); } return(View()); }
//GET API public ActionResult MyClassified() { using (AradaLejDBContext _context = new AradaLejDBContext()) { List <Online.Classified.App.Models.Classified> classifieds = _context.Classified.ToList(); return(Json(new { data = classifieds }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Detail(int Id) { using (AradaLejDBContext aradaLejContext = new AradaLejDBContext()) { var classifieds = aradaLejContext.Classified.Single(a => a.Id == Id); return(View(classifieds)); } }
public ActionResult Index(int Id) { using (AradaLejDBContext aradaLejContext = new AradaLejDBContext()) { var classifieds = aradaLejContext.Classified.OrderBy(a => a.Id).Where(a => a.CategoryId == Id).ToList(); return(View(classifieds)); } }
public ActionResult GetCategories() { using (AradaLejDBContext _context = new AradaLejDBContext()) { var categories = _context.Category.OrderBy(a => a.Id).ToList(); return(Json(new { data = categories }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Create(int Id) { using (AradaLejDBContext _context = new AradaLejDBContext()) { var category = _context.Category.Where(a => a.Id == Id).SingleOrDefault(); return(View(category)); } }
//Populates all classified categories public ActionResult Index() { using (AradaLejDBContext aradaLejContext = new AradaLejDBContext()) { var categorires = aradaLejContext.Category.OrderBy(a => a.Id).ToList(); return(View(categorires)); } }
public ActionResult ClassifiedList() { using (AradaLejDBContext aradaLejContext = new AradaLejDBContext()) { var classifieds = aradaLejContext.Classified.OrderBy(a => a.Id).ToList(); return(PartialView(classifieds)); //return Json(new { data = classifieds }, JsonRequestBehavior.AllowGet); } }
public ActionResult PostAd(int Id) { if (Session["user"] == null) { return(RedirectToAction("Index", "Home")); } using (AradaLejDBContext _context = new AradaLejDBContext()) { var category = _context.Category.Where(a => a.Status == true).ToList(); ViewBag.CategoryId = category; var ad = _context.Classified.Where(a => a.Id == Id).FirstOrDefault(); return(View(ad)); } }
public ActionResult PostAd(Models.Classified classified) { StringBuilder sbDescription = new StringBuilder(); sbDescription.Append(HttpUtility.HtmlEncode(classified.Description)); sbDescription.Replace("<b>", "<b>"); sbDescription.Replace("</b>", "</b>"); sbDescription.Replace("<u>", "<u>"); sbDescription.Replace("</u>", "</u>"); classified.Description = sbDescription.ToString(); string title = HttpUtility.HtmlEncode(classified.Title); classified.Title = title; if (ModelState.IsValid) { using (AradaLejDBContext _context = new AradaLejDBContext()) { if (classified.Id > 0) { //edit var v = _context.Classified.Where(a => a.Id == classified.Id).FirstOrDefault(); if (v != null) { v.CategoryId = classified.CategoryId; v.Title = classified.Title; v.PictureUrl = classified.PictureUrl; v.Description = classified.Description; v.Location = classified.Location; v.Price = classified.Price; v.PhoneNumber = classified.PhoneNumber; v.IsRecommended = Convert.ToBoolean(classified.IsRecommended); } } else { _context.Classified.Add(classified); } _context.SaveChanges(); } return(RedirectToAction("MyAds")); } return(View()); }
public ActionResult Delete(int Id) { bool result = false; using (AradaLejDBContext _context = new AradaLejDBContext()) { var c = _context.Category.Where(a => a.Id == Id).SingleOrDefault(); if (c != null) { _context.Category.Remove(c); _context.SaveChanges(); result = true; } return(Json(result, JsonRequestBehavior.AllowGet)); //return RedirectToAction("ManageCategory", "Category"); } }