Exemplo n.º 1
0
        public ActionResult RemoveFromFavourites(int adId)
        {
            using (HangerDatabase DataContext = new HangerDatabase())
            {
                int user = (Session["LogedUserID"] as User).Id;
                var fav  = (from s in DataContext.Favourite
                            where (s.UserId == user) && (s.AdId == adId)
                            select s).FirstOrDefault();

                DataContext.Favourite.Remove(fav);

                DataContext.SaveChanges();
                ViewBag.isInFavourites = false;
            }
            var ad = from s in db.Ad
                     select s;

            //ViewBag.AddCount = ad.Count();


            ViewBag.index = ad.ToList().FindIndex(a => a.Id == adId);
            ViewBag.ad    = adId;
            Ad advertisement = db.Ad.Find(adId);

            return(PartialView("AdToFavorites", ad.ToList()));
        }
Exemplo n.º 2
0
        public ActionResult AddToFavourites(int adId)
        {
            using (HangerDatabase db = new HangerDatabase())
            {
                Favourite f = new Favourite();
                f.Date_start = DateTime.Now;
                f.UserId     = (Session["LogedUserID"] as User).Id;


                if (db.Favourite != null && db.Favourite.Count() != 0)
                {
                    f.Id = (from ph in db.Favourite
                            select ph.Id).Max() + 1;
                }
                else
                {
                    f.Id = 0;
                }

                // p.OwnerId = (Session["CurrentUserEmail"] as User).UserId;
                f.AdId = adId;
                db.Favourite.Add(f);
                db.SaveChanges();
                ViewBag.isInFavourites = true;
                //return Json(f, JsonRequestBehavior.AllowGet);
            }

            //return RedirectToAction("New", "Home");
            //return RedirectToAction("Product", "Ad", new { id = adId });
            var ad = from s in db.Ad
                     select s;

            ViewBag.index = ad.ToList().FindIndex(a => a.Id == adId);
            return(PartialView("AdToFavorites", ad.ToList()));
        }
Exemplo n.º 3
0
        public ActionResult AddPhoto(int adId)
        {
            HttpPostedFileBase file = Request.Files[0];

            byte[] imageSize = new byte[file.ContentLength];
            file.InputStream.Read(imageSize, 0, (int)file.ContentLength);


            using (HangerDatabase db = new HangerDatabase())
            {
                Photos p = new Photos();
                p.Photo     = imageSize;
                p.FIle_name = file.FileName;

                if (db.Photos != null && db.Photos.Count() != 0)
                {
                    p.Id = (from ph in db.Photos
                            select ph.Id).Max() + 1;
                }
                else
                {
                    p.Id = 0;
                }

                // p.OwnerId = (Session["CurrentUserEmail"] as User).UserId;
                p.AdId       = adId;
                p.Type       = file.ContentType;
                p.Main_photo = false;
                db.Photos.Add(p);
                db.SaveChanges();
            }

            //return RedirectToAction("New", "Home");
            return(RedirectToAction("Photo1", "Ad", new { id = adId }));
        }
Exemplo n.º 4
0
        public ActionResult DeletePhoto(int id, int adId)
        {
            using (HangerDatabase DataContext = new HangerDatabase())
            {
                var photoToDelete = (from p in DataContext.Photos
                                     where p.Id == id
                                     select p).FirstOrDefault();

                DataContext.Photos.Remove(photoToDelete);
                DataContext.SaveChanges();
            }

            return(RedirectToAction("Photo1", "Ad", new { id = adId }));
        }
Exemplo n.º 5
0
        public ActionResult Delete(int adId)
        {
            using (HangerDatabase DataContext = new HangerDatabase())
            {
                var photoToDelete = (from p in DataContext.Photos
                                     where p.AdId == adId
                                     select p);
                while (photoToDelete.Count() > 0)
                {
                    DataContext.Photos.Remove(photoToDelete.FirstOrDefault());
                    DataContext.SaveChanges();
                }
                var ad = (from p in DataContext.Ad
                          where p.Id == adId
                          select p).FirstOrDefault();

                DataContext.Ad.Remove(ad);
                DataContext.SaveChanges();
            }

            return(RedirectToAction("UserProfil", "UserProfil", new { id = (Session["LogedUserID"] as Hanger.Models.User).Id }));
        }
Exemplo n.º 6
0
        public ActionResult IsSold(int adId)
        {
            using (HangerDatabase db = new HangerDatabase())
            {
                Ad A = db.Ad.Find(adId);
                if (ModelState.IsValid)
                {
                    A.Is_sold         = true;
                    A.Date_end        = DateTime.Now;
                    db.Entry(A).State = EntityState.Modified;
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                    {
                        Exception raise = dbEx;
                    }
                }
            }

            //return RedirectToAction("New", "Home");
            return(RedirectToAction("Product", "Ad", new { id = adId }));
        }