Exemple #1
0
        public IActionResult Create(AdModel model)
        {
            if (ModelState.IsValid)
            {
                // string title, decimal price, string location, string descritpion, string email, string phone

                var ad = new Ad()
                {
                    CategoryId  = model.CategoryId,
                    CreatedOn   = DateTime.Now,
                    Description = model.Description,
                    Email       = model.Email,
                    Location    = model.Location,
                    Price       = model.Price,
                    Telephone   = model.Phone,
                    Title       = model.Title,
                    Photo       = model.Photo
                };

                _ads.Create(ad);

                // ja viss OK, pārsūtām uz sludinājumu sadaļu
                return(RedirectToAction(nameof(MyAds), new { id = model.CategoryId }));
            }

            // kategorijas nepieciešams atlasīt arī POST pieprasījumā
            model.Categories = _categories.GetAll();
            return(View(model));
        }
        public ActionResult PostAd(AdModel model)
        {
            Ad ad = new Ad();

            ad.CategoryId  = model.CategoryId;
            ad.City        = model.City;
            ad.Description = model.Description;
            ad.Locality    = model.Locality;
            ad.PostedDate  = DateTime.Now;
            ad.Price       = model.Price;
            ad.Title       = model.Title;
            ad.ValidTill   = DateTime.Now.AddDays(30);
            ad.UserId      = CurrentUser.UserId;
            int adId = _adRepo.InsertAd(ad);

            if (adId > 0)
            {
                ViewBag.AdId = adId;
                var files = GetFiles();
                _adRepo.SaveAdImages(files, adId);
                return(View("adposted"));
            }
            else
            {
                ViewBag.Message = "Sorry there was error in posting  your ad";
                return(View(model));
            }
        }
        public HttpResponseMessage GetAd(System.Guid id)
        {
            AdModel ad = Mapper.Map <Ad, AdModel>(GetAdObject(id));

            if (ad != null)
            {
                ad = Mapper.Map <Ad, AdModel>(unitOfWork.AdRepository.GetByID(id));
                if (ad.ImagePath == "")
                {
                    ad.ImagePath = "../img/320x150.png";
                }
                else
                {
                    try
                    {
                        string filePath = Config.ImgRoot + ad.ImagePath;
                        ad.ImagePath = File.ReadAllText(filePath);
                    }
                    catch
                    {
                        ad.ImagePath = "../img/320x150.png";
                    }
                }

                ad.CityName     = unitOfWork.CityRepository.GetByID(ad.CityId).CityName;
                ad.CategoryName = unitOfWork.CategoryRepository.GetByID(ad.CategoryId).CatName;

                return(OK(ad));
            }
            else
            {
                return(NotFound("Ad not found."));
            }
        }
        public HttpResponseMessage UpdateSingle(AdModel ad)
        {
            Ad existingAd = null;

            existingAd = GetAdObject(ad.Id);

            existingAd.Description = ad.Description;
            existingAd.Email       = ad.Email;
            existingAd.Location    = ad.Location;
            existingAd.Name        = ad.Name;
            existingAd.PhoneNumber = ad.PhoneNumber;
            existingAd.Website     = CorrectWebiste(ad.Website);
            existingAd.CategoryId  = ad.CategoryId;
            existingAd.CityId      = ad.CityId;
            existingAd.longitude   = ad.longitude;
            existingAd.latitude    = ad.latitude;
            //


            try
            {
                unitOfWork.AdRepository.Update(existingAd);
                existingAd.ImagePath = replaceImgFile(ad.Id, ad.Date, ad.ImagePath);
                unitOfWork.Save();
                return(NoContent());
            }
            catch (Exception ex)
            {
                return(InternalServerError("Server Error: Can not update Ad in database.", ex));
            }
        }
Exemple #5
0
        public async Task <int> CreateAd(AdModel ad)
        {
            DynamicParameters parameters = new DynamicParameters();

            parameters.Add("Title", ad.Title);
            parameters.Add("DatePosted", ad.DatePosted);
            parameters.Add("Description", ad.Description);
            parameters.Add("Price", ad.Price);
            parameters.Add("ModelName", ad.ModelName);
            parameters.Add("Kilometers", ad.Kilometers);
            parameters.Add("CubicCapacity", ad.CubicCapacity);
            parameters.Add("HorsePower", ad.HorsePower);
            parameters.Add("Kilowatts", ad.Kilowatts);
            parameters.Add("ClientName", ad.ClientName);
            parameters.Add("Address", ad.Address);
            parameters.Add("City", ad.City);
            parameters.Add("ZIP", ad.ZIP);
            parameters.Add("Country", ad.Country);
            parameters.Add("Phone", ad.Phone);
            parameters.Add("ClientId", ad.ClientId);
            parameters.Add("BrandId", ad.BrandId);
            parameters.Add("CarBodyTypeId", ad.CarBodyTypeId);
            parameters.Add("CarConditionId", ad.CarConditionId);
            parameters.Add("ColorId", ad.ColorId);
            parameters.Add("FuelId", ad.FuelId);
            parameters.Add("ProductionYearId", ad.ProductionYearId);

            parameters.Add("Id", SqlDbType.Int, direction: ParameterDirection.Output);

            await _dataAccess.SaveData("[dbo].[spAds_CreateAd]",
                                       parameters,
                                       _connectionString.SqlConnectionString);

            return(parameters.Get <int>("Id"));
        }
Exemple #6
0
        public ActionResult updateAd(String id)
        {
            String  s = id;
            AdModel a = adRep.get1ad(s);

            return(View(a));
        }
Exemple #7
0
        /// <summary>Creates a random model of the specified type: 0 = Green, 1 = Orange, 2 = Ad</summary>
        SimpleBaseModel CreateRandomModel(int index, int type)
        {
            SimpleBaseModel model;

            if (type == 0)
            {
                model = new GreenModel()
                {
                    textContent = DemosUtil.GetRandomTextBody(10, 70)
                }
            }
            ;
            else if (type == 1)
            {
                model = new OrangeModel()
                {
                    value = UnityEngine.Random.Range(0f, 1f)
                }
            }
            ;
            else
            {
                model = new AdModel()
                {
                    adID      = Guid.NewGuid().ToString(),
                    adTexture = _AdTextures[UnityEngine.Random.Range(0, _AdTextures.Length)]
                };
            }

            return(model);
        }
Exemple #8
0
 public void GetAreaInfo()
 {
     model = bll.GetModel(Convert.ToInt32(_Pid));
     if (model != null)
     {
         this.txtTitle.Text = model.Title;
         this.txtLink.Text  = model.Link;
         this.txtSort.Text  = model.sort.ToString();
         if (!string.IsNullOrEmpty(model.Image))
         {
             ViewState["Image"]        = model.Image;
             this.uploadimage.ImageUrl = "~" + model.Image;
             disImg = "1";
         }
         else
         {
             ViewState["Image"]        = "";
             this.uploadimage.ImageUrl = "../images/nopic.jpg";
         }
         this.DrCategory.SelectedValue       = model.CategoryId.ToString();
         this.RadioButtonList1.SelectedValue = model.DisplayMode.ToString();
         this.txtStartTime.Text = Convert.ToDateTime(model.StartTime).ToString("yyyy-MM-dd");
         this.txtEndTime.Text   = Convert.ToDateTime(model.EndTime).ToString("yyyy-MM-dd");
     }
 }
        public ActionResult show(int adid)
        {
            Ad ad = _adRepo.GetAdById(adid);

            if (ad != null)
            {
                AdModel model = new AdModel();
                model.AdId       = ad.AdId;
                model.CategoryId = ad.CategoryId;
                model.City       = ad.City;
                if (ad.Description.Length > 215)
                {
                    ad.Description = ad.Description.Substring(0, 215) + ".....";
                }
                model.Description = ad.Description;
                model.Locality    = ad.Locality;
                model.Price       = ad.Price;
                model.Title       = ad.Title;
                model.ValidTill   = ad.ValidTill;
                model.UserId      = ad.UserId;
                model.PosdtedOn   = ad.PostedDate;
                var categories = Static.GetCategories();
                var cat        = categories.Where(t => t.CategoryId == ad.CategoryId).FirstOrDefault();
                model.CategoryName = cat.CategoryName;

                return(View(model));
            }
            else
            {
                ViewBag.Error = "Sorry , no such ad";
                return(View("Invalid"));
            }
        }
Exemple #10
0
/// <summary>
/// 更新信息
/// </summary>
        public int UpdateInfo(SqlTransaction trans, AdModel adModel, int AdId)
        {
            string key = "Cache_Ad_Model_" + AdId;

            CacheHelper.RemoveCache(key);
            return(adDAL.UpdateInfo(trans, adModel, AdId));
        }
        public async Task <bool> Update(AdModel ad)
        {
            try
            {
                AdModel entity = await _adRepo.FindAsync(ad.Id);

                entity.ano           = ad.ano;
                entity.Marca         = ad.Marca;
                entity.Modelo        = ad.Modelo;
                entity.Observacao    = ad.Observacao;
                entity.Quilometragem = ad.Quilometragem;
                entity.Versao        = ad.Versao;

                _adRepo.Update(entity);

                int changed = await _adRepo.Commit();

                if (changed > 0)
                {
                    return(true);
                }

                return(false);
            }
            catch (AppException ex)
            {
                throw new AppException(ex.Message, ex.Code);
            }
        }
        public async Task <bool> Create(AdModel ad)
        {
            try
            {
                AdModel _ad = new AdModel()
                {
                    ano           = ad.ano,
                    Marca         = ad.Marca,
                    Modelo        = ad.Modelo,
                    Observacao    = ad.Observacao,
                    Quilometragem = ad.Quilometragem,
                    Versao        = ad.Versao
                };
                await _adRepo.Add(_ad);

                int changed = await _adRepo.Commit();

                if (changed > 0)
                {
                    return(true);
                }

                return(false);
            }
            catch (AppException ex)
            {
                throw new AppException(ex.Message, ex.Code);
            }
        }
Exemple #13
0
        public ResultObj <List <AdModel> > GetData()
        {
            AdModel adInfo = new AdModel();
            var     ads    = _IBase.GetAll(adInfo);

            return(Content(ads));
        }
Exemple #14
0
        public void storeCSV(HttpPostedFileBase csvFile, List <Ad> list)
        {
            string path     = null;
            var    fileName = Path.GetFileName(csvFile.FileName);

            path = AppDomain.CurrentDomain.BaseDirectory + fileName;
            csvFile.SaveAs(path);
            FileStream   fs = new FileStream(path, FileMode.Open);
            StreamReader sr = new StreamReader(fs);
            //ignore first line concerns headers
            string headers = sr.ReadLine();
            //store each line
            string s = sr.ReadLine();

            //if not at the end of file
            while (s != null)
            {
                string[] ligne = s.Split(';');
                //skip irrelevant data
                while (String.IsNullOrWhiteSpace(ligne[6]) && String.IsNullOrWhiteSpace(ligne[7]))
                {
                    s     = sr.ReadLine();
                    ligne = s.Split(';');
                }
                if (String.IsNullOrWhiteSpace(ligne[6]))
                {
                    ligne[6] = "0";
                }
                if (String.IsNullOrWhiteSpace(ligne[7]))
                {
                    ligne[7] = "0";
                }
                //create a relevant ad
                Ad a = new Ad()
                {
                    Year          = Int32.Parse(ligne[0]),
                    Market        = ligne[1],
                    Segment       = ligne[2],
                    Brand         = ligne[3],
                    Copy_Duration = Int32.Parse(ligne[4]),
                    Copy_Name     = ligne[5],
                    Score_1       = Int32.Parse(ligne[6]),
                    Score_2       = Int32.Parse(ligne[7].Replace('%', ' '))
                };
                list.Add(a);
                s = sr.ReadLine();
            }
            //close the file
            sr.Close(); fs.Close();
            //adding of the ads in the database
            using (var context = new AdModel())
            {
                foreach (Ad ad in list)
                {
                    context.Ads.Add(ad);
                }
                context.SaveChanges();
            }
        }
Exemple #15
0
        public async Task <ActionResult> Details(int id)
        {
            User user = await _userManager.GetUserAsync(User);

            AdModel model = _adService.GetAdById(id, user.Id);

            return(View(model));
        }
Exemple #16
0
        public ActionResult DeleteConfirmed(int id)
        {
            AdModel adModel = db.AdModels.Find(id);

            db.AdModels.Remove(adModel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        private AdModel ParseAdItem(HtmlNode node)
        {
            var document = new HtmlDocument();

            document.LoadHtml(node.InnerHtml);

            var adId = node.Descendants(0)
                       .FirstOrDefault(n => n.ChildAttributes("data-ad-id").Count() > 0)
                       ?.GetAttributeValue("data-ad-id", null);

            var imageLink = string.Empty;

            var adHref = node.Descendants(0)
                         .FirstOrDefault(n => n.ChildAttributes("href").Count() > 0)
                         ?.GetAttributeValue("href", null);


            var headlineBlock = node.Descendants(0)
                                .FirstOrDefault(n => n.HasClass("headline-block"));

            var adTitle = headlineBlock.ChildNodes?.Count == 3 ?
                          headlineBlock.ChildNodes[1].InnerText
                : headlineBlock.ChildNodes[0].InnerText;



            var adLink = adHref;

            var carInfo = node.Descendants(0)
                          .FirstOrDefault(n => n.HasClass("rbt-regMilPow")).InnerText;

            var locationInfo = string.Empty; //node.Descendants(0)
            //    .Where(n => n.HasClass("g-col-10")).Last().InnerText;

            var priceInfo = node.Descendants(0)
                            .FirstOrDefault(n => n.HasClass("price-block")).InnerText;



            var adDateCreated = string.Empty;


            var model = new AdModel()
            {
                ProviderAdId  = HttpUtility.HtmlDecode(adId),
                AdTitle       = HttpUtility.HtmlDecode(adTitle),
                CarInfo       = HttpUtility.HtmlDecode(carInfo),
                ImageLink     = HttpUtility.HtmlDecode(imageLink),
                PriceInfo     = HttpUtility.HtmlDecode(priceInfo),
                AdSource      = AdSource.MobileDe,
                AddressInfo   = HttpUtility.HtmlDecode(locationInfo),
                CreatedAtInfo = HttpUtility.HtmlDecode(adDateCreated),
                AdLink        = adLink
            };


            return(model);
        }
        public static void InsertAd(int index, AdModel ad)
        {
            if (App.AdsListCache.Count >= AD_LIST_CACHE_SIZE)
            {
                App.AdsListCache.RemoveAt(AD_LIST_CACHE_SIZE - 1);
            }

            App.AdsListCache.Insert(index, ad);
        }
        public ActionResult Index()
        {
            AdModel a = new AdModel()
            {
            };
            List <AdModel> a1 = adRep.getalAdd();

            return(View(a1));
        }
Exemple #20
0
        public async Task <IActionResult> Post(AdModel ad)
        {
            var KW = Convert.ToInt32(ad.HorsePower) * 0.75;

            ad.Kilowatts = KW.ToString();

            int id = await _adDataAccess.CreateAd(ad);

            return(Ok(new { Id = id }));
        }
Exemple #21
0
        public async Task <IActionResult> Add(AdModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            await _service.AddAsync(model);

            return(RedirectToAction("Index", "Home"));
        }
Exemple #22
0
        public IActionResult Add()
        {
            var model = new AdModel()
            {
                Address = new AddressModel(),
                Owner   = new UserModel()
            };

            return(View(model));
        }
Exemple #23
0
 public ActionResult Edit([Bind(Include = "ID,IdCar,IsActive")] AdModel adModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(adModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(adModel));
 }
Exemple #24
0
        public IActionResult Create()     //get funkcijai iekavās nekas nav nepieciešams
        {
            AdModel model = new AdModel();

            model.Email      = HttpContext.Session.GetUserEmail();
            model.Categories = _categories.GetAll();


            return(View(model));
        }
Exemple #25
0
        public void AddAd(string imgsrc, string imglink, string imgalt, uint pagelevel)
        {
            AdModel ad = new AdModel();

            ad.imgsrc    = imgsrc;
            ad.imglink   = imglink;
            ad.pagelevel = (int)pagelevel;

            db.InsertSingleLine <AdModel>("ad", ad);
        }
Exemple #26
0
        public IActionResult Create()
        {
            AdModel model = new AdModel();

            model.Email = HttpContext.Session.GetUserEmail();

            model.Categories = _categories.GetAll();

            return(View(model));
        }
Exemple #27
0
        public async Task <bool> AddAd([FromBody] AdModel ad)
        {
            var result = await _adContract.AddAd(_mapper.Map <AdModel, AdPOCO>(ad));

            if (result)
            {
                return(true);
            }
            return(false);
        }
Exemple #28
0
 public ActionResult Edit([Bind(Include = "AdId,Name,Description,Owner")] AdModel adModel)
 {
     if (ModelState.IsValid)
     {
         adModel.Owner           = User.Identity.Name;
         db.Entry(adModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(adModel));
 }
Exemple #29
0
        public int InsertAd(AdModel ads)
        {
            SqlParameter[] param = { new SqlParameter("@Name", SqlDbType.VarChar, 20), new SqlParameter("@PhotoPath", SqlDbType.VarChar, 255),
                                     new SqlParameter("@Url",  SqlDbType.VarChar, 255) };
            param[0].Value = ads.AdName;
            param[1].Value = ads.PhotoPath;
            param[2].Value = ads.Url;
            int result = SqlHelp.ExecuteNonQuery("prc_InsertAd", CommandType.StoredProcedure, param);

            return(result);
        }
Exemple #30
0
        public ActionResult Create([Bind(Include = "ID,IdCar,IsActive")] AdModel adModel)
        {
            if (ModelState.IsValid)
            {
                db.AdModels.Add(adModel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(adModel));
        }
 public ParkingPlaceAdvertisementModel(List<ParkingPlaceModel> list, AdModel ad)
 {
     ParkingPlaces = list;
     Ad = ad;
 }