public ActionResult Create(BrandAdvice brandAdvice, FormCollection form)
        {
            if (brandAdvice.BrandsId == null)
            {
                ModelState.AddModelError("BrandsId", "Please choose a brand...");
            }
            ValidateAdvice(brandAdvice);

            if (ModelState.IsValid)
            {
                try
                {
                    var mentor = CurrentMentor;

                    _adviceApplicationService.AddBrandAdvice(mentor, brandAdvice);

                    return(RedirectToAction("Index", "Advice"));
                }
                catch
                {
                    return(RedirectToAction("Create"));
                }
            }
            var brands = _brandApplicationService.GetAllBrands();

            ViewData["Brands"]     = new SelectList(brands, "Id", "BrandName", brandAdvice.BrandsId);
            ViewData["Semaphores"] = _semaphoreApplicationService.GetAllSemaphores();
            SetAdviceTagViewData();
            return(View(brandAdvice));
        }
Example #2
0
 public BrandAdvice AddBrandAdvice(Mentor mentor, BrandAdvice adviceToAdd)
 {
     if (adviceToAdd.BrandsId == null)
     {
         throw new ArgumentException("BrandsId cannot be null when adding BrandAdvice");
     }
     using (var brandRepository = _repositoryFactory.Build <IRepository <Brand>, Brand>())
     {
         var brand = brandRepository.FindOne(x => x.Id == adviceToAdd.BrandsId);
         return(AddAdvice(mentor, adviceToAdd, brand));
     }
 }
        public ActionResult Edit(BrandAdvice brandAdvice, FormCollection form)
        {
            ValidateAdvice(brandAdvice);
            if (ModelState.IsValid)
            {
                _adviceApplicationService.UpdateAdvice(brandAdvice);
                return(RedirectToAction("Index", "Advice"));
            }
            SetAdviceTagViewData();
            ViewData["Semaphores"] = _semaphoreApplicationService.GetAllSemaphores();
            var advice = _adviceApplicationService.GetAdvice(brandAdvice.Id.Value) as BrandAdvice;
            var brand  = _brandApplicationService.GetBrand(advice.BrandsId.Value);

            ViewData["Brand"] = brand;
            return(View(advice));
        }