Example #1
0
        public void ActionsByInventarizationsWorks()
        {
//            DELETE FROM public."Tasks";
//DELETE FROM public."Users";
//DELETE FROM public."Actions";
//DELETE FROM public."Zones";
//DELETE FROM public."Inventorizations";
//DELETE FROM public."Companies"

            User user = userRepositoriy.CreateUser(new User()
            {
                FirstName = "test_name", FamilyName = "test_family", MiddleName = "test_middlename", Level = UserLevel.Scaner, CreatedAt = DateTime.UtcNow, Login = "******", Password = "******"
            });
            Company company = companyRepositoriy.CreateCompany("Тест1");

            Business.Model.Inventorization inventarisation = inventorizationRepositoriy.CreateInventorization(company.Id, DateTime.UtcNow);
            Guid firstActionId  = Guid.NewGuid();
            Guid secondActionId = Guid.NewGuid();

            Business.Model.Action firstAction = new Business.Model.Action()
            {
                Id              = firstActionId,
                DateTime        = DateTime.UtcNow,
                Type            = ActionType.FirstScan,
                UserId          = user.Id,
                Inventorization = inventarisation.Id,
                BarCode         = "1",
                Quantity        = 1,
            };

            Business.Model.Action secondAction = new Business.Model.Action()
            {
                Id       = firstActionId,
                DateTime = DateTime.UtcNow,
                Type     = ActionType.FirstScan,
                UserId   = user.Id,
                Zone     = inventarisation.Id,
                BarCode  = "1",
                Quantity = 1,
            };

            actionRepository.CreateAction(firstAction);
            actionRepository.CreateAction(secondAction);
            List <Business.Model.Action> actions = actionRepository.GetActionsByInventorization(inventarisation.Id);

            Assert.IsNotNull(actions);
            Assert.AreEqual(2, actions.Count());

            actionRepository.DeleteAction(firstActionId);
            actionRepository.DeleteAction(secondActionId);
            inventorizationRepositoriy.DeleteInventorization(inventarisation.Id);
            companyRepositoriy.DeleteCompany(company.Id);
            userRepositoriy.DeleteUser(user.Id);
        }
Example #2
0
        public void CreateCompanySuccessfully()
        {
            var content = File.ReadAllText("../../../Fixtures/companies_create.json");

            var client = GetMockClient(content);
            var repo   = new CompanyRepository(client.Object);
            var resp   = repo.CreateCompany(new Dictionary <string, object>
            {
                { "legal_name", "Test company #1" },
                { "name", "Test company #1" },
                { "country", "AUS" },
                { "tax_number", string.Empty },
                { "charge_tax", string.Empty },
                { "address_line1", string.Empty },
                { "address_line2", string.Empty },
                { "city", string.Empty },
                { "state", string.Empty },
                { "zip", string.Empty }
            });

            client.VerifyAll();
            var returnedCompany = resp.Values.First();
            var createdCompany  = JsonConvert.DeserializeObject <IDictionary <string, object> >(JsonConvert.SerializeObject(returnedCompany));

            Assert.IsNotNull(createdCompany);
            Assert.IsNotNull(createdCompany["id"]);
            Assert.AreEqual("Test company #1", (string)createdCompany["legal_name"]);
        }
Example #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                await FetchData().ConfigureAwait(false);

                return(this.TurboPage());
            }

            if (!await FetchData().ConfigureAwait(false))
            {
                return(RedirectToPage("/Index"));
            }

            return((await companies.CreateCompany(new Company
            {
                CompanyName = Input.CompanyName,
                CompanyAddress = Input.CompanyAddress,
                CompanyPostcode = Input.CompanyPostcode,
                CompanyContact = Input.CompanyContact,
                CompanyPhone = Input.CompanyPhone,
                CompanyEmail = Input.CompanyEmail,
                ReferenceCode = Guid.NewGuid().ToString()
            })
                    .Ensure(c => c.HasValue, "Company was created")
                    .OnSuccess(c => this.RedirectToPage("/Company", new {
                companyId = c.Value
            }))
                    .OnFailure(() => this.Page())
                    .ConfigureAwait(false)).Value);
        }
Example #4
0
        public async Task <IResponse> CreateCompanyConfiguration(CompanyModel company)
        {
            var newCompanyConfiguration = new CompanyModel(company.CompanyName, company.CompanyIdentificationNumber, company.Country, company.TaxRates);

            newCompanyConfiguration.OwnerId = company.OwnerId; //TODO add a new constructor with owner id
            var result = await _companyRepository.CreateCompany(newCompanyConfiguration);

            return(new MessageResponse("Company settings updated"));
        }
Example #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            var name  = textBox1.Text;
            var phone = textBox2.Text;

            if (CompanyRepository.CreateCompany(name, phone))
            {
                var addOrderForm = new AddOrderForm();
                addOrderForm.FillCompanies();
                MessageBox.Show("Eklendi.");
            }
            else
            {
                MessageBox.Show("Hata.");
            }
        }
 public ActionResult NewCompany(NewCompany companyData)
 {
     if (ModelState.IsValid)
     {
         CompanyRepository repo = new CompanyRepository(new BaseContext());
         if (repo.IsValid(companyData))
         {
             var id = repo.CreateCompany(new Company(companyData), User.Identity.GetUserId <int>());
             return(Redirect("Account/MyCompany/" + id));
         }
         else
         {
             ModelState.AddModelError("Name", "Данное имя уже занято!");
         }
     }
     return(View(companyData));
 }
Example #7
0
        public void CreateCompanySuccessfully()
        {
            var content = File.ReadAllText("../../../Fixtures/companies_create.json");

            var client         = GetMockClient(content);
            var repo           = new CompanyRepository(client.Object);
            var userId         = "ec9bf096-c505-4bef-87f6-18822b9dbf2c";
            var createdCompany = repo.CreateCompany(new Company
            {
                LegalName = "Test company #1",
                Name      = "Test company #1",
                Country   = "AUS"
            }, userId);

            client.VerifyAll();
            Assert.IsNotNull(createdCompany);
            Assert.IsNotNull(createdCompany.Id);
        }
Example #8
0
        public async Task <IActionResult> CreateCompany([FromBody] DtoCreateCompanyRequest request)
        {
            if (ModelState.ValidationState != ModelValidationState.Valid)
            {
                return(BadRequest());
            }

            return(await companies.CreateCompany(new Company
            {
                CompanyName = request.CompanyName,
                CompanyAddress = request.CompanyAddress,
                CompanyPostcode = request.CompanyPostcode,
                CompanyContact = request.CompanyContact,
                CompanyPhone = request.CompanyPhone,
                CompanyEmail = request.CompanyEmail
            })
                   .Ensure(companyId => companyId.HasValue, "Company created")
                   .OnSuccess(companyId => companies.FetchCompany(companyId.Value))
                   .Ensure(company => company.HasValue, "Company exists")
                   .OnSuccess(company => RegisterBillingAccount(company.Value, request))
                   .OnBoth(result => result.IsFailure ? StatusCode(500) : StatusCode(201))
                   .ConfigureAwait(false));
        }
 public bool CreateCompany(Company company)
 {
     return(_repository.CreateCompany(company));
 }
Example #10
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            ViewData["HideNavigation"] = true;

            returnUrl ??= Url.Content("~/");

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var company = await companies.CreateCompany(new Company
            {
                CompanyName     = Input.CompanyName,
                CompanyPhone    = Input.CompanyPhone,
                CompanyPostcode = Input.CompanyPostcode,
                CompanyContact  = Input.CompanyContact,
                CompanyEmail    = Input.CompanyEmail,
                CompanyAddress  = Input.CompanyAddress
            }).Ensure(c => c.HasValue, "Company created")
                          .OnSuccess(c => c.Value)
                          .ConfigureAwait(false);

            if (company.IsFailure)
            {
                ModelState.AddModelError(string.Empty, "Something went wrong when confirming your details, sorry about that. Please reach out to our support team to finish your setup.");
                return(Page());
            }

            var venue = await venues.CreateVenue(new Venue {
                CompanyId        = company.Value,
                VenueCode        = "",
                VenueName        = Input.VenueName,
                VenueAddress     = "",
                VenuePostCode    = "",
                VenuePhone       = "",
                VenueContact     = "",
                VenueDescription = "",
                VenueNotes       = "Created via onboarding",
            }).Ensure(c => c.HasValue, "Venue created")
                        .OnSuccess(c => c.Value)
                        .ConfigureAwait(false);

            if (venue.IsFailure)
            {
                ModelState.AddModelError(string.Empty, "Something went wrong when confirming your details, sorry about that. Please reach out to our support team to finish your setup.");
                return(Page());
            }

            var user = new Employee {
                Username = Input.EmployeeEmail, EmployeeName = Input.EmployeeName, CompanyId = company.Value, VenueId = venue.Value, RoleId = 5
            };
            var result = await _userManager.CreateAsync(user, Input.EmployeePassword).ConfigureAwait(false);

            if (result.Succeeded)
            {
                result = await _userManager.UpdateSecurityStampAsync(user).ConfigureAwait(false);

                if (result.Succeeded)
                {
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user).ConfigureAwait(false);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));

                    _logger.LogInformation("User created a new account with password.");

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.EmployeeId, code, returnUrl },
                        protocol: Request.Scheme
                        );

                    await _emailSender.SendEmailAsync(Input.EmployeeEmail, "Welcome to Koasta!",
                                                      $@"
                            <p>Thanks for choosing Koasta. You're on your way to accepting digital payments with ease.</p>
                            <p>Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>. After confirming, you'll have access to your Koasta dashboard and can begin your onboarding process.</p>
                            <p>Further information about how to get started with Koasta can be found <a href='https://support.koasta.com'>here</a>.</p>
                        ").ConfigureAwait(false);

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.EmployeeEmail, returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false).ConfigureAwait(false);

                        return(LocalRedirect(returnUrl));
                    }
                }
            }

            try
            {
                await venues.DropVenue(venue.Value).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
            }

            try
            {
                await companies.DropCompany(company.Value).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
            }

            if (!result.Errors.Any(e => e.Code.Equals("TOOCOMMON", StringComparison.OrdinalIgnoreCase)))
            {
                ModelState.AddModelError(string.Empty, "Something went wrong when confirming your details, sorry about that. Please reach out to our support team to finish your setup.");
            }

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

            // If we got this far, something failed, redisplay form
            return(Page());
        }