Exemplo n.º 1
0
        public ActionResult Index()
        {
            AddingAdsRepository model = new AddingAdsRepository();

            model.CategoryID = -1;
            model.Categories = addingAdsRepository.GetList();
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult AddAdvertisement()
        {
            if (Session["ID"] != null)
            {
                AddingAdsRepository model = new AddingAdsRepository();
                model.CategoryID = -1;
                model.Categories = addingAdsRepository.GetList();

                return(View(model));
            }
            return(RedirectToAction("Logowanie", "home"));
        }
Exemplo n.º 3
0
        public ActionResult EditAdvertisement(EditAdModel obj)
        {
            if (Session["ID"] != null)
            {
                var AdID = obj.ID;
                AddingAdsRepository model = new AddingAdsRepository();
                model.CategoryID = -1;
                model.Categories = addingAdsRepository.GetList();
                ADVERTS AdData = new AdvertRepository().GetAdData(AdID);

                return(View(AdData));
            }
            else
            {
                return(RedirectToAction("Logowanie", "Home"));
            }
        }
Exemplo n.º 4
0
        public ActionResult AddAdvertisement(AddingAdsRepository AddingAdsRepository, IEnumerable <HttpPostedFileBase> files)
        {
            if (ModelState.IsValid)
            {
                int     uID       = Convert.ToInt32(Session["ID"]);
                ADVERTS newAdvert = new ADVERTS();

                newAdvert.CATEGORY    = AddingAdsRepository.CategoryID;
                newAdvert.TITLE       = AddingAdsRepository.Advert.TITLE;
                newAdvert.USER_ID     = uID;
                newAdvert.DESCRIPTION = AddingAdsRepository.Advert.DESCRIPTION;
                newAdvert.DATE        = System.DateTime.Now;
                newAdvert.IS_ARCHIVED = false;
                newAdvert.IS_HIDDEN   = false;
                Convert.ToString(AddingAdsRepository.Advert.PRICE);
                var areTermsAccepted = AddingAdsRepository.AreTermsAccepted(AddingAdsRepository);
                if (AddingAdsRepository.Advert.PRICE == null)
                {
                    newAdvert.PRICE = 0;
                }
                else
                {
                    newAdvert.PRICE = AddingAdsRepository.Advert.PRICE;
                }


                if (areTermsAccepted)
                {
                    AddingAdsRepository.Categories = addingAdsRepository.GetList();
                    AddingAdsRepository.CategoryID = -1;
                    ModelState.AddModelError("TERMS", "Należy zaakceptować regulamin");
                    return(View(AddingAdsRepository));
                }
                else if (newAdvert.CATEGORY != 1)
                {
                    foreach (var file in files)
                    {
                        if (file != null)
                        {
                            //var file = model.ImageFile;
                            var filename       = Guid.NewGuid() + file.FileName;
                            var supportedTypes = new[] { "jpg", "jpeg", "png", "JPG", "JPEG", "PNG" };
                            var fileExt        = System.IO.Path.GetExtension(file.FileName).Substring(1);
                            if (!supportedTypes.Contains(fileExt))
                            {
                                return(Content("<script language='javascript' type='text/javascript'>alert('Niebsługiwany typ pliku. Dozwolone formaty: .jpg .jpeg .png');location = location;</script>"));
                            }
                            else
                            {
                                file.SaveAs(Server.MapPath("/UploadImage/" + filename));
                                BinaryReader  reader = new BinaryReader(file.InputStream);
                                IMAGES_ADVERT img    = new IMAGES_ADVERT();

                                if (file.ContentLength > 5242880)  // 2MB?
                                {
                                    return(Content("<script language='javascript' type='text/javascript'>alert('Plik jest zbyt duży');location = location;</script>"));
                                }

                                else
                                {
                                    img.IMAGE_TITLE = filename;
                                    img.IMAGE_PATH  = "/UploadImage/" + filename;
                                    img.ADVERT_ID   = newAdvert.ID;
                                    db.IMAGES_ADVERT.Add(img);
                                    db.ADVERTS.Add(newAdvert);
                                }
                            }
                        }
                        else
                        {
                            db.ADVERTS.Add(newAdvert);
                        }
                    }
                    db.SaveChanges();
                    return(RedirectToAction("MojeOgloszenia", "adverts"));
                }
                else
                {
                    AddingAdsRepository.Categories = addingAdsRepository.GetList();
                    AddingAdsRepository.CategoryID = -1;
                    ModelState.AddModelError("CATEGORY", "Musisz wybrać kategorię z listy.");
                    return(View(AddingAdsRepository));
                }
            }
            AddingAdsRepository.Categories = addingAdsRepository.GetList();
            AddingAdsRepository.CategoryID = -1;
            return(View(AddingAdsRepository));
        }