Beispiel #1
0
        public ActionResult Create(ProductAdvice productAdvice, FormCollection form)
        {
            if (productAdvice.ProductsId == null)
            {
                ModelState.AddModelError("ProductsId", "Please choose a product.");
            }
            ValidateAdvice(productAdvice);
            productAdvice.MentorId = CurrentMentor.Id;

            if (ModelState.IsValid)
            {
                try
                {
                    //_adviceApplicationService.AddProductAdvice(CurrentMentor, productAdvice);
                    _productAdviceApplicationService.SaveProductAdvice(productAdvice);
                    return(RedirectToAction("Index", "Advice"));
                }
                catch
                {
                    return(RedirectToAction("Create"));
                }
            }
            var products = _productApplicationService.GetAllProducts();

            ViewData["Products"]   = new SelectList(products, "Id", "ProductName", productAdvice.ProductsId);
            ViewData["Semaphores"] = _semaphoreApplicationService.GetAllSemaphores();
            SetAdviceTagViewData();
            return(View(productAdvice));
        }
Beispiel #2
0
        public bool SaveProductAdvice(ProductAdvice productAdvice)
        {
            if (!productAdvice.Id.HasValue || productAdvice.Id == 0)
            {
                var product = _productRepository.FindOne(p => p.Id == productAdvice.ProductsId);
                product.ProductAdvices.Add(productAdvice);
                _productRepository.Persist();
                return(true);
            }
            else
            {
                var product = GetProductForAdvice(productAdvice.Id.Value);

                if (product == null)
                {
                    return(false);
                }
                var advice = product.ProductAdvices.Single(a => a.Id == productAdvice.Id);
                SetSemaphore(productAdvice.SemaphoreId, advice);
                SetTag(productAdvice.TagId, advice);
                advice.CopyStringProperties(productAdvice);
                advice.Published = productAdvice.Published;
                _productRepository.Persist();
                return(true);
            }
        }
Beispiel #3
0
 public ProductAdvice AddProductAdvice(Mentor mentor, ProductAdvice adviceToAdd)
 {
     if (adviceToAdd.ProductsId == null)
     {
         throw new ArgumentException("ProductsId cannot be null when adding ProductAdvice");
     }
     using (var productRepository = _repositoryFactory.Build <IRepository <Product>, Product>())
     {
         var product = productRepository.FindOne(x => x.Id == adviceToAdd.ProductsId);
         return(AddAdvice(mentor, adviceToAdd, product));
     }
 }
Beispiel #4
0
        public ProductAdvice BuildProductAdvice(Mentor mentor, Semaphore semaphore)
        {
            var productAdvice = new ProductAdvice()
            {
                Advice       = "Sveriges Konsumenter anmälde Coca Cola för vilseledande GDA-märkning av sina Coca Cola-flaskor. Att en flaska om 500 ml skulle utgöra två portioner framstår som vilseledande, likaså det faktum att företaget använder två olika portionsstorlekar när det beräknar GDA.",
                Introduction = "Coca Cola anmält för vilseledande GDA-märkning av dryckesflaskor.",
                KeyWords     = "Coca-Cola, Mer",
                Label        = "Svenska nyheter",
                Mentor       = mentor,
                Semaphore    = semaphore,
                Published    = true,
                PublishDate  = DateTime.Now
            };

            return(productAdvice);
        }
Beispiel #5
0
        private void SetSemaphore(int?semaphoreId, ProductAdvice adviceToAdd)
        {
            if (!semaphoreId.HasValue)
            {
                throw new ArgumentException("Semaphore not set");
            }

            var semaphore = _productRepository.FindSemaphore(semaphoreId.Value);

            if (semaphore == null)
            {
                string exceptonMessage = "No Semaphore found when trying to add Advice";
                Log.Error(exceptonMessage);
                throw new NullReferenceException(exceptonMessage);
            }
            adviceToAdd.Semaphore = semaphore;
        }
Beispiel #6
0
 public ActionResult Edit(ProductAdvice productAdvice, FormCollection form)
 {
     ValidateAdvice(productAdvice);
     if (ModelState.IsValid)
     {
         productAdvice.MentorId = CurrentMentor.Id;
         _productAdviceApplicationService.SaveProductAdvice(productAdvice);
         //_adviceApplicationService.UpdateAdvice(productAdvice);
         return(RedirectToAction("Index", "Advice"));
     }
     return(Edit(productAdvice.Id.Value));
     //SetAdviceTagViewData();
     //ViewData["Semaphores"] = _semaphoreApplicationService.GetAllSemaphores();
     //var advice = _adviceApplicationService.GetAdvice(productAdvice.Id.Value) as ProductAdvice;
     //var product = _productApplicationService.GetProduct(advice.ProductsId.Value);
     //ViewData["Product"] = product;
     //return View(advice);
 }
 public void DeleteProductAdvice(ProductAdvice advice)
 {
     Delete(advice);
 }