Exemplo n.º 1
0
        public async Task CreateCompanyAsyncTest_WhitCorrectData_ShouldReturnTrue()
        {
            var context = SteuDbContextInMemoryFactory.InitializeContext();

            MapperInitializer.InitializeMapper();
            var repository = new EfDeletableEntityRepository <Company>(context);

            var service = new CompaniesService(repository);

            var model = new CreateCompanyBindingModel()
            {
                Name       = "Test Ltd",
                UIC        = "123123123",
                UserId     = "asdasd asd asd asd ",
                LicenseUrl = "dadadasdadasd",
            };

            var user = new SteuUser()
            {
                Id = "asdadas",
            };

            var actualResult = await service.CreateCompanyAsync(model, user);

            Assert.True(actualResult);
        }
Exemplo n.º 2
0
        public async Task <bool> CreateCompanyAsync(CreateCompanyBindingModel model, SteuUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("User is null");
            }

            if (model.Name == null)
            {
                throw new ArgumentNullException("Company name is null");
            }

            if (model.UIC == null)
            {
                throw new ArgumentNullException("UIC is null");
            }

            Company company = new Company()
            {
                Name       = model.Name,
                UIC        = model.UIC,
                LicenseUrl = model.LicenseUrl,
            };

            company.Employees.Add(user);

            await this.companyRepositori.AddAsync(company);

            await this.companyRepositori.SaveChangesAsync();

            return(true);
        }
        public async Task CreateCompany(CreateCompanyBindingModel model)
        {
            var company = new Company();

            company.Name      = model.Name;
            company.IsDeleted = model.IsDeleted;

            await dbContext.Companies.AddAsync(company);

            await dbContext.SaveChangesAsync();
        }
Exemplo n.º 4
0
        public async Task <IActionResult> CreateCompany(CreateCompanyBindingModel model)
        {
            if (ModelState.IsValid)
            {
                await service.CreateCompany(model);

                return(Redirect("DisplayAllCompanies"));
            }
            else
            {
                return(View());
            }
        }
Exemplo n.º 5
0
        public async Task CreateCompanyAsyncTest_WhitNullUser_ShouldReturnArgumentNullException()
        {
            var context = SteuDbContextInMemoryFactory.InitializeContext();

            MapperInitializer.InitializeMapper();
            var repository = new EfDeletableEntityRepository <Company>(context);

            var service = new CompaniesService(repository);

            var model = new CreateCompanyBindingModel()
            {
                Name       = "Test Ltd",
                UIC        = "123123123",
                UserId     = "asdasd asd asd asd ",
                LicenseUrl = "dadadasdadasd",
            };

            await Assert.ThrowsAsync <ArgumentNullException>(() => service.CreateCompanyAsync(model, null));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? this.Url.Content("~/Identity/Account/Login");

            if (this.Input.LicenseUrl == null)
            {
                this.ModelState.AddModelError("FileURL", "Please upload file");
            }

            if (this.ModelState.IsValid)
            {
                var user = new SteuUser {
                    UserName = this.Input.Username,
                    Email    = this.Input.Email, FirstName = this.Input.FirstName, LastName = this.Input.LastName
                };
                var result = await _userManager.CreateAsync(user, this.Input.Password);

                if (result.Succeeded)
                {
                    //_logger.LogInformation("User created a new account with password.");

                    //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    //var callbackUrl = Url.Page(
                    //    "/Account/ConfirmEmail",
                    //    pageHandler: null,
                    //    values: new { userId = user.Id, code = code },
                    //    protocol: Request.Scheme);

                    //await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                    //    $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (await _userManager.Users.CountAsync() == 1)
                    {
                        await _userManager.AddToRoleAsync(user, GlobalConstants.AdministratorRoleName);

                        await _userManager.AddToRoleAsync(user, GlobalConstants.ModeratorRoleName);

                        await this.usersService.ChangeUserIsAuthorizeSatusByUserIdAsync(user.Id, "true");
                    }
                    else
                    {
                        await _userManager.AddToRoleAsync(user, GlobalConstants.OwnerRoleName);

                        await this.usersService.ChangeUserIsAuthorizeSatusByUserIdAsync(user.Id, "false");
                    }

                    var licenseUrl = await this.cloudinaryService.UploadPictureAsync(this.Input.LicenseUrl, this.Input.LicenseUrl.FileName);

                    CreateCompanyBindingModel model = new CreateCompanyBindingModel()
                    {
                        Name       = this.Input.Company,
                        UIC        = this.Input.UIC,
                        UserId     = user.Id,
                        LicenseUrl = licenseUrl,
                    };

                    await this.usersService.SetMenagerByIdAsync(user.Id);

                    await _companiesService.CreateCompanyAsync(model, user);

                    return(this.LocalRedirect(returnUrl));
                }

                foreach (var error in result.Errors)
                {
                    this.ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(this.Page());
        }
Exemplo n.º 7
0
        public async Task <IActionResult> CreateCompany()
        {
            var newCompany = new CreateCompanyBindingModel();

            return(View(newCompany));
        }