示例#1
0
 public IActionResult Add(AddMasterViewModel model)
 {
     if (ModelState.IsValid)
     {
         var fileUrl = new FileSaver.FileSaver().Save(model.Photo, PhotoUrl);
         var res     = _commandDispatcher.Dispatch(new AddMasterCommand()
         {
             FirstName        = model.FirstName,
             LastName         = model.LastName,
             Description      = model.Description,
             ShortDescription = model.ShortDescription,
             PhotoUrl         = fileUrl
         });
         if (res.IsSuccess)
         {
             return(RedirectToAction("Index"));
         }
         ModelState.AddModelError("", res.Message);
         foreach (string item in res.Errors)
         {
             ModelState.AddModelError("", item);
         }
     }
     return(View());
 }
示例#2
0
 public IActionResult AddCategory(AddCategoryViewModel model)
 {
     if (ModelState.IsValid)
     {
         var fileUrl = new FileSaver.FileSaver().Save(model.Photo, PhotoUrl);
         var result  = _commandDispatcher.Dispatch(new AddCategoryCommand
         {
             Name     = model.Name,
             ParentId = model.ParentId,
             PhotoUrl = fileUrl
         });
         if (result.IsSuccess)
         {
             return(RedirectToAction("Index"));
         }
         ModelState.AddModelError("", result.Message);
         foreach (string item in result.Errors)
         {
             ModelState.AddModelError("", item);
         }
     }
     return(View(model));
 }