public ActionResult Edit(int id, ProjectAccountModel account) { try { InitializePageData(); if (ModelState.IsValid) { if (accountsService.Exists(account.AccountName, account.AccountID)) { DisplayWarningMessage($"ProjectAccount Name '{account.AccountName}' is duplicate"); return(View(account)); } if (accountsService.IsDuplicateShortName(account.AccountID, account.ShortName)) { DisplayWarningMessage($"This Short Name '{account.ShortName}' is duplicate"); return(View(account)); } ProjectAccountDto accountModel = Mapper.Map <ProjectAccountModel, ProjectAccountDto>(account); accountsService.Update(accountModel); DisplaySuccessMessage($"Account '{account.AccountName}' details have been modified successfully"); return(RedirectToAction("List")); } } catch (Exception exp) { DisplayUpdateErrorMessage(exp); } return(View(account)); }
public ActionResult Create(ProjectAccountModel account) { try { InitializePageData(); if (ModelState.IsValid) { if (accountsService.Exists(account.AccountName)) { DisplayWarningMessage($"This Account Name '{account.AccountName}' is duplicate"); return(View(account)); } if (accountsService.IsDuplicateShortName(account.ShortName)) { DisplayWarningMessage($"This Short Name '{account.ShortName}' is duplicate"); return(View(account)); } ProjectAccountDto accountModel = Mapper.Map <ProjectAccountModel, ProjectAccountDto>(account); accountsService.Add(accountModel); DisplaySuccessMessage($"New Account '{account.AccountName}' has been stored successfully"); return(RedirectToAction("List")); } } catch (Exception exp) { DisplayLoadErrorMessage(exp); } return(View(account)); }
// GET: Accounts/Edit/5 public ActionResult Edit(int?id) { ProjectAccountModel account = new ProjectAccountModel(); InitializePageData(); try { if (!id.HasValue) { DisplayWarningMessage("Looks like, the ID is missing in your request"); return(RedirectToAction("List")); } if (!accountsService.Exists(id.Value)) { DisplayWarningMessage($"Sorry, We couldn't find the Account with ID: {id.Value}"); return(RedirectToAction("List")); } ProjectAccountDto accountDto = accountsService.GetByID(id.Value); account = Mapper.Map <ProjectAccountDto, ProjectAccountModel>(accountDto); } catch (Exception exp) { DisplayReadErrorMessage(exp); } return(View(account)); }