daily pastebin goal
4%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Is this a valid way to code up an MVC Service Layer?
  2. protected bool ValidateAccount(Account account)
  3.         {
  4.             var accounts = _accountRepository.GetPk(account.PartitionKey);
  5.             if (accounts.Any(b => b.Title.Equals(account.Title) &&
  6.                                   !b.RowKey.Equals(account.RowKey)))
  7.                 _validationDictionary.AddError("", "Duplicate title");
  8.             return _validationDictionary.IsValid;
  9.         }
  10.    
  11. public bool Create(Account account)
  12. {
  13.     if (!ValidateAccount(account))
  14.         return false;
  15.     try
  16.     {
  17.         _accountRepository.AddOrUpdate(account);
  18.     }
  19.     catch
  20.     {
  21.         return false;
  22.     }
  23.     return true;
  24. }
  25.    
  26. public ActionResult Create(BaseViewModel vm)
  27. {
  28.     _accountService = new AccountService(new ModelStateWrapper(this.ModelState), vm.Meta.DataSourceID);
  29.     if (ModelState.IsValid)
  30.     {
  31.  
  32.             _accountService = new AccountService(new ModelStateWrapper(this.ModelState), vm.Meta.DataSourceID);
  33.             if (!_accountService.Create(vm.Account))
  34.                 return View("CreateEdit", vm);
  35.             else
  36.                 return RedirectToAction("Created");
  37.         }
  38.         return RedirectToAction("Home");
  39.     }
  40.     return View("CreateEdit", vm);
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top