Esempio n. 1
0
        public async Task <ActionResult <AccountVM> > Create([FromBody] AccountVM accountVM)
        {
            // Validation
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Mapping
            Account account = this.mapper.Map <AccountVM, Account>(accountVM);

            // BLL
            User currentUser = await userManager.GetUserAsync(User);

            AccountBLL bll = new AccountBLL(this.unitOfWork, currentUser);

            // Create
            Account newAccount;

            try
            {
                newAccount = await bll.CreateAccount(account);
            }
            catch (CrmException ex)
            {
                return(BadRequest(this.mapper.Map <CrmException, CrmExceptionVM>(ex)));
            }

            // Mapping
            return(CreatedAtAction("GetById", new { id = newAccount.Id }, this.mapper.Map <Account, AccountVM>(newAccount)));
        }
Esempio n. 2
0
 public ActionResult CreateAccount(Account account)
 {
     account.UserRole = "User";
     if (ModelState.IsValid)
     {
         ViewBag.Message = accountBll.CreateAccount(account);
     }
     return(View());
 }