public void AddAdvertisement(int userId, AdvertisementModel ad)
        {
            if (ad.Features == null || ad.Features.Count() == 0)
                    throw new ArgumentNullException("Invalid argument");
                Advertisement adv = new Advertisement();
                adv.StartDate = ad.StartDate;
                adv.EndDate = ad.EndDate;

                Product product = new Product() { ProductGroupID=ad.Category,Description=ad.Title};
                foreach (ProductFeature productFeature in ad.Features)
                {
                    product.ProductProperties.Add(new ProductProperty()
                    {
                        ProductGroupPropertyID =Int32.Parse( productFeature.Key),
                        Value = productFeature.Value
                    });
                }
                adv.Product = product;
                adv.OwnerID = userId;
                adv.Price = ad.Price;
                adv.Title = ad.Title;
                adv.IsActive = true;

                dbContext.Advertisements.Add(adv);
                dbContext.SaveChanges();
        }
        public ActionResult CreateProduct()
        {
            var keys = Request.Form.AllKeys;
            List<ProductFeature> features = new List<ProductFeature>();
            foreach (var key in keys.Where(x => !reservedKeys.Contains( x)))
            {
                features.Add(new ProductFeature { Key = key, Value = Request[key] });
            }
            DateTime startDate=DateTime.Now;
            DateTime endDate = DateTime.Now.AddMonths(1);
            //DateTime.TryParse(Request.Form["StartDate"],out startDate);
            //DateTime.TryParse(Request.Form["FinishDate"], out endDate);
            AdvertisementModel ad = new AdvertisementModel() { Features = features };
            ad.StartDate = startDate;
            ad.EndDate = endDate;
            ad.Title = Request.Form["Title"];
            ad.Price = decimal.Parse(Request.Form["Price"]);
            ad.Category = Int32.Parse(Request.Form["CategoryId"]);

            productRepository.AddAdvertisement(WebSecurity.GetUserId(User.Identity.Name), ad);
            return RedirectToAction("AdList", "Ad");
        }
        public void UpdateAdvertisement(AdvertisementModel advertisementModel)
        {
            if (advertisementModel.Features == null || advertisementModel.Features.Count() == 0)
                throw new ArgumentNullException();

            var ad =( from adv in dbContext.Advertisements
                                            .Include("Product")
                                            .Include("Product.ProductProperties")
                      where adv.AdvertisementID == advertisementModel.Id
                      select adv).Single();

            var properties = dbContext.ProductProperties.Where(pp => pp.ProductID == ad.ProductID);
            var product = dbContext.Products.Single(p => p.ProductID == ad.ProductID);
            dbContext.ProductProperties.RemoveRange(properties);

            ad.StartDate = advertisementModel.StartDate;
            ad.EndDate = advertisementModel.EndDate;
            ad.Price = advertisementModel.Price;
            ad.Title = advertisementModel.Title;
            ad.IsActive = true;

            product.Description = advertisementModel.Title ;
            foreach (ProductFeature productFeature in advertisementModel.Features)
            {
                product.ProductProperties.Add(new ProductProperty()
                {
                    ProductGroupPropertyID = Int32.Parse(productFeature.Key),
                    Value = productFeature.Value
                });
            }
            dbContext.SaveChanges();
        }
 public void UpdateAdvertisement(AdvertisementModel product)
 {
     throw new NotImplementedException();
 }
 public void AddAdvertisement(string userName,AdvertisementModel product)
 {
     throw new NotImplementedException();
 }