Exemplo n.º 1
0
        public ActionResult Create(FormCollection collection, Article ent)
        {
            try
            {
                ent.ID = Guid.NewGuid().ToString();
                ArticleCreateOrUpdateCommand cmd = new ArticleCreateOrUpdateCommand(ent);
                commandBus.Submit(cmd);

                return RedirectToAction("Index");
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var item in ex.EntityValidationErrors)
                {
                    foreach (var citem in item.ValidationErrors)
                    {
                        ModelState.AddModelError(citem.PropertyName, citem.ErrorMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }
            return View();
        }
Exemplo n.º 2
0
 public ActionResult Edit(string id, FormCollection collection, Article ent)
 {
     try
     {
         // TODO: Add update logic here
         var oldent = articleRepository.Get(s => s.ID == id);
         ObjectHelper.CopyProperties<Article>(ent, oldent);
         oldent.ID = id;
         ArticleCreateOrUpdateCommand cmd = new ArticleCreateOrUpdateCommand(oldent);
         commandBus.Submit(cmd);
         return RedirectToAction("Index");
     }
     catch (DbEntityValidationException ex)
     {
         foreach (var item in ex.EntityValidationErrors)
         {
             foreach (var citem in item.ValidationErrors)
             {
                 ModelState.AddModelError(citem.PropertyName, citem.ErrorMessage);
             }
         }
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", ex.Message);
     }
     return View();
 }