Ejemplo n.º 1
0
        public async Task <RollsCreateServiceModel> CreateAsync(decimal entryPrice, int currencyId, decimal entryPriceTaxPercent, decimal maxSum)
        {
            var activeRollFound = this.HasActiveRoll();

            if (activeRollFound == true)
            {
                throw new InvalidOperationException(ErrorMessages.AlreadyActiveRoll);
            }

            var currencyFound = this.currenciesService.IsPresent(currencyId);

            if (currencyFound == false)
            {
                throw new ArgumentException(ErrorMessages.CurrencyNotFound);
            }

            var roll = new Roll
            {
                IsActive   = true,
                EntryFee   = entryPrice,
                CurrencyId = currencyId,
                CutPercent = entryPriceTaxPercent,
                MaxSum     = maxSum
            };

            await db.Rolls.AddAsync(roll);

            await db.SaveChangesAsync();

            var serviceModel = new RollsCreateServiceModel
            {
            };

            return(serviceModel);
        }
Ejemplo n.º 2
0
        public async Task <ErrorsRegisterServiceModel> RegisterAsync(string method, string path, string message, string stackTrace, string userId, string information)
        {
            var error = new Error
            {
                Method      = method,
                Path        = path,
                Message     = message,
                StackTrace  = stackTrace,
                UserId      = userId,
                Information = information
            };

            await db.Errors.AddAsync(error);

            await db.SaveChangesAsync();

            var serviceModel = new ErrorsRegisterServiceModel
            {
            };

            return(serviceModel);
        }
        public async Task <IActionResult> Seed()
        {
            if (db.Users.Any())
            {
                return(Ok("Database is not empty"));
            }

            var stringBuilder = new StringBuilder();

            var user = new User
            {
                UserName    = AdministratorUserValues.UserName,
                Email       = AdministratorUserValues.Email,
                PhoneNumber = AdministratorUserValues.PhoneNumber,
            };
            var roles = new List <Role>
            {
                new Role
                {
                    Name        = "User",
                    Information = "Basic role."
                },
                new Role
                {
                    Name        = "Administrator",
                    Information = "Administrator role gives full access to the platoform."
                },
            };
            var currencies = new List <Currency>
            {
                new Currency
                {
                    Name    = "USD",
                    IsoCode = "USD",
                    Symbol  = "$",
                },
                new Currency
                {
                    Name    = "EUR",
                    IsoCode = "EUR",
                    Symbol  = "€"
                }
            };

            await userManager.CreateAsync(user, AdministratorUserValues.Passowrd);

            foreach (var role in roles)
            {
                await roleManager.CreateAsync(role);
            }

            foreach (var curency in currencies)
            {
                await db.Currencies.AddAsync(curency);
            }

            await userManager.AddToRoleAsync(user, Roles.Administrator);

            await db.SaveChangesAsync();

            stringBuilder.AppendLine($"Registered user: {user.Email}");
            stringBuilder.AppendLine($"Registered roles: {string.Join(" ", roles.Select(role => role.Name))}");
            stringBuilder.AppendLine($"Registered currencies: {string.Join(" ", currencies.Select(currency => currency.Name))}");

            var response = stringBuilder.ToString();

            return(Ok(response));
        }