Beispiel #1
0
        public IActionResult Delete(int id)
        {
            var cli = ctx.Clients.Find(id);

            ctx.Remove(cli);
            ctx.SaveChanges();
            return(View(cli));
            //return RedirectToAction("index");
        }
Beispiel #2
0
        private void SeedExchangeAccounts(ClientsDbContext db)
        {
            if (!db.ExchangeAccounts.Any())
            {
                var client = db.Clients.FirstOrDefault(c => c.Id == 2);

                var exchangeAccounts = new List <ExchangeAccount>()
                {
                    new ExchangeAccount()
                    {
                        Id             = 1,
                        Balance        = 100,
                        IdentityNumber = "123456789101",
                        CreatedAt      = DateTime.UtcNow,
                        IsActive       = true,
                        OwnerId        = client.Id,
                        TypeId         = 1
                    },
                    new ExchangeAccount()
                    {
                        Id             = 2,
                        Balance        = 200,
                        IdentityNumber = "123456789109",
                        CreatedAt      = DateTime.UtcNow,
                        IsActive       = false,
                        ClosedAt       = DateTime.UtcNow,
                        OwnerId        = client.Id,
                        TypeId         = 1
                    }
                };

                db.ExchangeAccounts.AddRange(exchangeAccounts);
                db.SaveChanges();
            }
        }
        private static void SeedExchangeAccountTypes(ClientsDbContext db)
        {
            if (db.ExchangeAccountTypes.Any())
            {
                return;
            }

            var accountTypes = new List <ExchangeAccountType>()
            {
                new ExchangeAccountType()
                {
                    Name        = "Standard",
                    Description = "An account that is for regular purposes - sending and receiving money."
                },
                new ExchangeAccountType()
                {
                    Name        = "Savings",
                    Description = "An account that is used for storing large amount of money for future use."
                },
                new ExchangeAccountType()
                {
                    Name        = "Combined",
                    Description = "An account that is used for savings and for regular payments."
                }
            };

            foreach (var exchangeAccountType in accountTypes)
            {
                db.ExchangeAccountTypes.Add(exchangeAccountType);
            }

            db.SaveChanges();
        }
        private static void SeedTransactions(ClientsDbContext db)
        {
            if (db.Transactions.Any() || !db.ExchangeAccounts.Any())
            {
                return;
            }

            var exchangeAccountIds = db.ExchangeAccounts.Select(a => a.Id).ToList();

            var availableDescriptions = new List <string>()
            {
                "Funding of an account",
                "Withdrawing money",
                "Rent for month June 2020",
                "Salary for month June 2020",
                "Car Leasing",
                "Mortgage June 2020",
                "Cat food.",
                "Fantastiko bill 100.99",
            };

            var random = new Random();

            var maxTransactionsCount = 30;

            for (var i = 0; i < maxTransactionsCount; i++)
            {
                var senderIndex      = random.Next(0, exchangeAccountIds.Count);
                var receiverIndex    = random.Next(0, exchangeAccountIds.Count);
                var descriptionIndex = random.Next(0, availableDescriptions.Count);

                var transaction = new Transaction()
                {
                    SenderAccountId   = exchangeAccountIds[senderIndex],
                    ReceiverAccountId = exchangeAccountIds[receiverIndex],
                    Description       = availableDescriptions[descriptionIndex],
                    Amount            = random.Next(10, 5000),
                    IssuedAt          = DateTime.UtcNow
                };

                db.Transactions.Add(transaction);
            }

            db.SaveChanges();
        }
Beispiel #5
0
        private void SeedClients(ClientsDbContext db)
        {
            if (!db.Clients.Any())
            {
                var clients = new List <Client>()
                {
                    new Client()
                    {
                        Id               = 1,
                        FirstName        = "Pesho",
                        LastName         = "Peshov",
                        Address          = "Yambol",
                        UserId           = "PeshoPeshov",
                        ExchangeAccounts = new List <ExchangeAccount>(),
                        Funds            = new List <Fund>()
                    },
                    new Client()
                    {
                        Id               = 2,
                        FirstName        = "Kiro",
                        LastName         = "Kirov",
                        Address          = "Sofia",
                        UserId           = "KiroKirov",
                        ExchangeAccounts = new List <ExchangeAccount>(),
                        Funds            = new List <Fund>()
                    },
                    new Client()
                    {
                        Id               = 3,
                        FirstName        = "Stamat",
                        LastName         = "Stamatov",
                        Address          = "Burgas",
                        UserId           = "StamatStamatov",
                        ExchangeAccounts = new List <ExchangeAccount>(),
                        Funds            = new List <Fund>()
                    }
                };

                db.Clients.AddRange(clients);
                db.SaveChanges();
            }
        }
Beispiel #6
0
        public IActionResult CreateOrder(CreateOrderDtoRequest request)
        {
            if (request.Wyroby == null || request.Wyroby.Count == 0)
            {
                return(BadRequest("Zamowienie musi miec min 1 wyrob"));
            }

            foreach (var i in request.Wyroby)
            {
                if (_context.WyrobCukierniczy.Any(s => s.Nazwa == i.Wyrob))
                {
                    return(BadRequest("Podano nieistniejacy wyrob"));
                }
            }

            var wyroby = _context.WyrobCukierniczy
                         .Where(w => request.Wyroby.Any(r => r.Wyrob == w.Nazwa));

            var newOrder = new Zamowienie
            {
                DataPrzyjecia = request.DataPrzyjecia,
                Uwagi         = request.Uwagi
            };

            var newOrderProduct = request.Wyroby.Select(w => new
                                                        Zamowienie_WyrobCukierniczy
            {
                Ilosc            = w.Ilosc,
                Uwagi            = w.Uwagi,
                Zamowienie       = newOrder,
                WyrobCukierniczy = _context.WyrobCukierniczy.Where(ww => ww.Nazwa == w.Wyrob).First()
            });


            _context.Zamowienie.Add(newOrder);
            //_context.Zamowienie_WyrobCukierniczy.AddRange(newOrderProduct);
            _context.SaveChanges();

            return(Ok());
        }
Beispiel #7
0
        private void SeedFunds(ClientsDbContext db)
        {
            if (!db.Funds.Any())
            {
                var client  = db.Clients.FirstOrDefault(c => c.Id == 2);
                var account = db.ExchangeAccounts.FirstOrDefault(a => a.OwnerId == client.Id && a.IsActive);

                var funds = new List <Fund>()
                {
                    new Fund()
                    {
                        Id        = 1,
                        Amount    = 100,
                        AccountId = account.Id,
                        ClientId  = client.Id,
                        IssuedAt  = DateTime.UtcNow
                    }
                };

                db.Funds.AddRange(funds);
                db.SaveChanges();
            }
        }
Beispiel #8
0
        private void SeedExchangeAccountTypes(ClientsDbContext db)
        {
            if (!db.ExchangeAccountTypes.Any())
            {
                var exchangeAccountTypes = new List <ExchangeAccountType>()
                {
                    new ExchangeAccountType()
                    {
                        Id          = 1,
                        Description = "Test Type",
                        Name        = "Test"
                    },
                    new ExchangeAccountType()
                    {
                        Id          = 2,
                        Description = "Another Test Type",
                        Name        = "Another Test"
                    }
                };

                db.ExchangeAccountTypes.AddRange(exchangeAccountTypes);
                db.SaveChanges();
            }
        }
 public virtual void Update(T entity)
 {
     context.Set <T>().Attach(entity);
     context.Entry(entity).State = EntityState.Modified;
     context.SaveChanges();
 }
 public int Complete()
 {
     return(_context.SaveChanges());
 }
        private static void SeedClients(ClientsDbContext db, IIdentityService identityService)
        {
            if (db.Clients.Count() > 1)
            {
                return;
            }

            var userIds = identityService.GetRegisteredUserIds().GetAwaiter().GetResult();

            if (userIds == null || !userIds.Any())
            {
                return;
            }

            var clients = new List <Client>()
            {
                new Client()
                {
                    Address   = "Sofia, str. Ivan Vazov 2",
                    FirstName = "Admin",
                    LastName  = "Exchangerat"
                },
                new Client()
                {
                    Address   = "Varna, str. Chataldja 2",
                    FirstName = "Hristina",
                    LastName  = "Ivanova"
                },
                new Client()
                {
                    Address   = "Burgas, str. Strandja 10",
                    FirstName = "Koko",
                    LastName  = "Kokov"
                },
                new Client()
                {
                    Address   = "Sliven, str. Ayshe 22",
                    FirstName = "Kolio",
                    LastName  = "Kolev"
                },
                new Client()
                {
                    Address   = "Elhovo, str. Kavkaz 1",
                    FirstName = "Pesho",
                    LastName  = "Peshev"
                },
                new Client()
                {
                    Address   = "Yambol, str. Elena Ivanova 50",
                    FirstName = "Stamat",
                    LastName  = "Stamatov"
                }
            };

            for (var i = 0; i < userIds.Count; i++)
            {
                clients[i].UserId = userIds.ElementAt(i);
            }

            db.Clients.AddRange(clients);
            db.SaveChanges();
        }
        private static void SeedExchangeAccounts(ClientsDbContext db)
        {
            if (db.ExchangeAccounts.Any() || !db.Clients.Any() || !db.ExchangeAccountTypes.Any())
            {
                return;
            }

            var clientIds = db.Clients.Select(c => c.Id).ToList();

            var exchangeAccountTypeIds = db.ExchangeAccountTypes.Select(t => t.Id).ToList();

            var random = new Random();

            var exchangeAccounts = new List <ExchangeAccount>()
            {
                new ExchangeAccount()
                {
                    Balance = random.Next(1000, 100000), CreatedAt = DateTime.UtcNow, IdentityNumber = "EXRT123456"
                },
                new ExchangeAccount()
                {
                    Balance = random.Next(1000, 100000), CreatedAt = DateTime.UtcNow, IdentityNumber = "EXRT714587"
                },
                new ExchangeAccount()
                {
                    Balance = random.Next(1000, 100000), CreatedAt = DateTime.UtcNow, IdentityNumber = "EXRT999158"
                },
                new ExchangeAccount()
                {
                    Balance = random.Next(1000, 100000), CreatedAt = DateTime.UtcNow, IdentityNumber = "EXRT789123"
                },
                new ExchangeAccount()
                {
                    Balance = random.Next(1000, 100000), CreatedAt = DateTime.UtcNow, IdentityNumber = "EXRT333145"
                },
                new ExchangeAccount()
                {
                    Balance = random.Next(1000, 100000), CreatedAt = DateTime.UtcNow, IdentityNumber = "EXRT568254"
                },
                new ExchangeAccount()
                {
                    Balance = random.Next(1000, 100000), CreatedAt = DateTime.UtcNow, IdentityNumber = "EXRT454759"
                },
                new ExchangeAccount()
                {
                    Balance = random.Next(1000, 100000), CreatedAt = DateTime.UtcNow, IdentityNumber = "EXRT456789"
                },
                new ExchangeAccount()
                {
                    Balance = random.Next(1000, 100000), CreatedAt = DateTime.UtcNow, IdentityNumber = "EXRT111567"
                },
                new ExchangeAccount()
                {
                    Balance = random.Next(1000, 100000), CreatedAt = DateTime.UtcNow, IdentityNumber = "EXRT879777"
                },
                new ExchangeAccount()
                {
                    Balance = random.Next(1000, 100000), CreatedAt = DateTime.UtcNow, IdentityNumber = "EXRT222121"
                },
                new ExchangeAccount()
                {
                    Balance = random.Next(1000, 100000), CreatedAt = DateTime.UtcNow, IdentityNumber = "EXRT456781"
                },
                new ExchangeAccount()
                {
                    Balance = random.Next(1000, 100000), CreatedAt = DateTime.UtcNow, IdentityNumber = "EXRT998875"
                }
            };

            foreach (var exchangeAccount in exchangeAccounts)
            {
                var userIndex        = random.Next(0, clientIds.Count);
                var accountTypeIndex = random.Next(0, exchangeAccountTypeIds.Count);

                exchangeAccount.OwnerId = clientIds[userIndex];
                exchangeAccount.TypeId  = exchangeAccountTypeIds[accountTypeIndex];

                db.ExchangeAccounts.Add(exchangeAccount);
            }

            db.SaveChanges();
        }