示例#1
0
 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());
 }
示例#2
0
 //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));
     }
 }
示例#3
0
 public ActionResult Detail(int Id)
 {
     using (AradaLejDBContext aradaLejContext = new AradaLejDBContext())
     {
         var classifieds = aradaLejContext.Classified.Single(a => a.Id == Id);
         return(View(classifieds));
     }
 }
示例#4
0
 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));
     }
 }
示例#5
0
 public ActionResult GetCategories()
 {
     using (AradaLejDBContext _context = new AradaLejDBContext())
     {
         var categories = _context.Category.OrderBy(a => a.Id).ToList();
         return(Json(new { data = categories }, JsonRequestBehavior.AllowGet));
     }
 }
示例#6
0
 public ActionResult Create(int Id)
 {
     using (AradaLejDBContext _context = new AradaLejDBContext())
     {
         var category = _context.Category.Where(a => a.Id == Id).SingleOrDefault();
         return(View(category));
     }
 }
示例#7
0
 //Populates all classified categories
 public ActionResult Index()
 {
     using (AradaLejDBContext aradaLejContext = new AradaLejDBContext())
     {
         var categorires = aradaLejContext.Category.OrderBy(a => a.Id).ToList();
         return(View(categorires));
     }
 }
示例#8
0
 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);
     }
 }
示例#9
0
        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));
            }
        }
示例#10
0
        public ActionResult PostAd(Models.Classified classified)
        {
            StringBuilder sbDescription = new StringBuilder();

            sbDescription.Append(HttpUtility.HtmlEncode(classified.Description));
            sbDescription.Replace("&lt;b&gt;", "<b>");
            sbDescription.Replace("&lt;/b&gt;", "</b>");
            sbDescription.Replace("&lt;u&gt;", "<u>");
            sbDescription.Replace("&lt;/u&gt;", "</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());
        }
示例#11
0
        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");
            }
        }