public async Task <IHttpActionResult> Register_Company(RegisterCompany model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = new ApplicationUser()
            {
                UserName = model.Email, Email = model.Email
            };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                var UserId = UserManager.FindByEmail(model.Email);
                CompanyProvider.SaveCompanyInfo(model, UserId.Id);
                CompanyProvider.SaveCategory(model, UserId.Id);
                UserManager.AddToRole(UserId.Id, "Company");
            }

            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }

            return(Ok());
        }
Пример #2
0
        public async Task <IHttpActionResult> RegisterCompany(RegisterCompanyBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            using (LoanAndRepayEntities entities = new LoanAndRepayEntities())
            {
                var companyName = entities.CompanyInfoes.FirstOrDefault(x => x.CompanyName == model.CompanyName);
                if (companyName == null)
                {
                    var user = new ApplicationUser()
                    {
                        UserName = model.Email, Email = model.Email
                    };

                    IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        var UserId = UserManager.FindByEmail(model.Email);
                        //Calling provider to save data
                        CompanyProvider.SaveCompanyInfo(model, UserId.Id);
                        UserManager.AddToRole(UserId.Id, "Company");
                    }
                    if (!result.Succeeded)
                    {
                        return(GetErrorResult(result));
                    }

                    return(Ok());
                }
            }
            return(BadRequest("Company name is already taken"));
        }