public async Task <IActionResult> Edit(int id, OpportunityFormModel model)
        {
            if (!await this.ValidateUserIsMemberOfOpportunityAsync(id))
            {
                return(Unauthorized());
            }

            if (!ModelState.IsValid)
            {
                model.PotentialMembers = await GetUsersInOpportunityMemberRoleAsync();

                return(View(model));
            }

            var serviceModel = await this.opportunities.GetByIdAsync(id);

            if (serviceModel == null)
            {
                return(BadRequest());
            }

            await this.opportunities.EditAsync(
                id,
                model.Name,
                model.Description,
                model.OportunityMembers);

            TempData.AddSuccessMessage($"Opportunity {model.Name} edited successfully!");
            return(RedirectToAction(nameof(Details), routeValues: new { id = id }));
        }
        public async Task <IActionResult> Create(int accountId)
        {
            if (!await this.ValidateUserIsAssignedAccountManager(accountId))
            {
                return(Unauthorized());
            }

            var model = new OpportunityFormModel
            {
                AccountId        = accountId,
                PotentialMembers = await GetUsersInOpportunityMemberRoleAsync()
            };

            return(View(model));
        }
        public async Task <IActionResult> Create(OpportunityFormModel model)
        {
            if (!await this.ValidateUserIsAssignedAccountManager(model.AccountId))
            {
                return(Unauthorized());
            }

            if (!ModelState.IsValid)
            {
                model.PotentialMembers = await GetUsersInOpportunityMemberRoleAsync();

                return(View(model));
            }

            await this.opportunities.CreateAsync(
                model.Name,
                model.Description,
                model.AccountId,
                model.OportunityMembers
                );

            TempData.AddSuccessMessage($"Opportunity {model.Name} created successfully!");
            return(RedirectToAction(controllerName: "Accounts", actionName: nameof(AccountsController.Details), routeValues: new { id = model.AccountId }));
        }