Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Is this a valid way to code up an MVC Service Layer?
- protected bool ValidateAccount(Account account)
- {
- var accounts = _accountRepository.GetPk(account.PartitionKey);
- if (accounts.Any(b => b.Title.Equals(account.Title) &&
- !b.RowKey.Equals(account.RowKey)))
- _validationDictionary.AddError("", "Duplicate title");
- return _validationDictionary.IsValid;
- }
- public bool Create(Account account)
- {
- if (!ValidateAccount(account))
- return false;
- try
- {
- _accountRepository.AddOrUpdate(account);
- }
- catch
- {
- return false;
- }
- return true;
- }
- public ActionResult Create(BaseViewModel vm)
- {
- _accountService = new AccountService(new ModelStateWrapper(this.ModelState), vm.Meta.DataSourceID);
- if (ModelState.IsValid)
- {
- _accountService = new AccountService(new ModelStateWrapper(this.ModelState), vm.Meta.DataSourceID);
- if (!_accountService.Create(vm.Account))
- return View("CreateEdit", vm);
- else
- return RedirectToAction("Created");
- }
- return RedirectToAction("Home");
- }
- return View("CreateEdit", vm);
- }
Add Comment
Please, Sign In to add comment