Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 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);
 }