public async Task <IActionResult> PutOwnerBank(Guid id, OwnerBank ownerBank)
        {
            if (id != ownerBank.Id)
            {
                return(BadRequest());
            }

            _context.Entry(ownerBank).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OwnerBankExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #2
0
        public async Task <IActionResult> PutPromotion(int id, Promotion promotion)
        {
            if (id != promotion.Id)
            {
                return(BadRequest());
            }

            _context.Entry(promotion).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PromotionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutTransaction(string id, Transaction transaction)
        {
            if (id != transaction.Id)
            {
                return(BadRequest(new ResponseResult("Id trong giao dịch phải giống nhau")));
            }

            _context.Entry(transaction).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TransactionExists(id))
                {
                    return(BadRequest(new ResponseResult("Không tìm thấy giao dịch!")));
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #4
0
        public async Task <IActionResult> PutTransactionHistory(string id, TransactionHistory transactionHistory)
        {
            if (id != transactionHistory.Id)
            {
                return(BadRequest());
            }

            _context.Entry(transactionHistory).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TransactionHistoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutOrderDetail(string id, OrderDetail orderDetail)
        {
            if (id != orderDetail.Id)
            {
                return(BadRequest());
            }

            _context.Entry(orderDetail).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderDetailExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #6
0
        public async Task <IActionResult> PutReview(string id, Review review)
        {
            if (id != review.Id)
            {
                return(BadRequest());
            }

            _context.Entry(review).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReviewExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #7
0
        public async Task <IActionResult> PutWallet(string id, WalletViewModel wallet)
        {
            if (id != wallet.Id)
            {
                return(BadRequest());
            }

            try
            {
                var currentWallet = await _context.Wallets.Where(x => x.Id == id).FirstOrDefaultAsync();

                var user = await _context.AppUsers.Where(x => x.Id.ToString() == currentWallet.UserId).FirstOrDefaultAsync();

                var newCoin          = wallet.Coin - currentWallet.Coin;
                var newPromotionCoin = wallet.PromotionCoin - currentWallet.PendingCoin;

                var transactionHistory = new TransactionHistory
                {
                    Id                     = Guid.NewGuid().ToString(),
                    UserId                 = wallet.UserId,
                    BillStatus             = BillStatus.Completed,
                    Coin                   = Math.Abs(newCoin),
                    DateCreated            = DateTime.Now,
                    Status                 = Status.Active,
                    TransactionHistoryType = (newCoin > 0) ? TransactionHistoryType.PayIn : TransactionHistoryType.Withdraw,
                };

                string notifyTransaction = " đã nạp ";
                if (transactionHistory.TransactionHistoryType == TransactionHistoryType.Withdraw)
                {
                    notifyTransaction = " đã rút ";
                }

                transactionHistory.Content = "Tài khoản " + user.UserName + notifyTransaction + newCoin + " vào lúc " + transactionHistory.DateCreated.ToString("dd/MM/yyyy hh:mm:ss tt");

                _context.TransactionHistories.Add(transactionHistory);


                currentWallet.PromotionCoin = wallet.PromotionCoin;
                currentWallet.Coin          = wallet.Coin;
                _context.Wallets.Update(currentWallet);


                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WalletExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #8
0
        public async Task <ActionResult <BankCard> > DeleteBankCard(string id)
        {
            var bankCard = await _context.BankCards.FindAsync(id);

            if (bankCard == null)
            {
                return(NotFound());
            }

            _context.BankCards.Remove(bankCard);
            await _context.SaveChangesAsync();

            return(bankCard);
        }
예제 #9
0
        // Đăng ký thường không qua tài khoản nào

        public async Task <bool> Register(AppUserViewModel request)
        {
            var user = new AppUser()
            {
                DateOfBirth         = request.DateOfBirth,
                Email               = request.Email,
                FirstName           = (string.IsNullOrEmpty(request.FirstName))? request.FirstName: "",
                LastName            = (string.IsNullOrEmpty(request.LastName)) ? request.LastName : "",
                UserName            = request.UserName,
                PhoneNumber         = request.PhoneNumber,
                Avatar              = request.Avatar,
                NickName            = request.NickName,
                TransactionPassword = request.TransactionPassword,
                Id = Guid.NewGuid()
            };

            if (!string.IsNullOrEmpty(request.RootUserId))
            {
                // generate link ref
                var rootUser = _context.AppUsers.Where(x => x.Id.ToString() == request.RootUserId).FirstOrDefault();
                if (rootUser != null)
                {
                    user.RootUserId      = rootUser.Id;
                    user.RefRegisterLink = DomainConsts.LotteryDomain + "/api/Users/register/" + user.Id.ToString();
                }
            }
            // create wallet
            var wallet = new Wallet
            {
                DateCreated   = DateTime.Now,
                Coin          = 0,
                PendingCoin   = 0,
                PromotionCoin = 0,
                Status        = Status.Active,
                WalletId      = TextHelper.RandomString(10),
                Id            = Guid.NewGuid().ToString(),
                UserId        = ""
            };

            _context.Wallets.Add(wallet);

            await _context.SaveChangesAsync();

            var newWallet = _context.Wallets.Where(x => string.IsNullOrEmpty(x.UserId)).FirstOrDefault();

            user.WalletId = newWallet.WalletId;

            var result = await _userManager.CreateAsync(user, request.Password);

            if (result.Succeeded)
            {
                newWallet.UserId = user.Id.ToString();

                await _context.SaveChangesAsync();

                var createdUser = await _context.AppUsers.Where(x => x.Id == user.Id).FirstOrDefaultAsync();

                var createdUserView = Mapper.Map <AppUser, AppUserViewModel>(createdUser);
                return(true);
            }
            else
            {
                _context.Wallets.Remove(newWallet);
                await _context.SaveChangesAsync();

                string error = "";
                foreach (var e in result.Errors)
                {
                    error += e.Description;
                }
                return(false);
            }
        }
예제 #10
0
        public async Task <IActionResult> SeedData()
        {
            try
            {
                if (_context.AppUsers.ToList().Count == 0)
                {
                    var user = new AppUser()
                    {
                        DateOfBirth         = DateTime.Now,
                        Email               = "*****@*****.**",
                        FirstName           = "Admin",
                        LastName            = "Lottery",
                        UserName            = "******",
                        PhoneNumber         = "0900000000",
                        Avatar              = "",
                        NickName            = "Adminstrator",
                        TransactionPassword = "******",
                        RefRegisterLink     = "",
                        WalletId            = ""
                    };
                    var result = await _userManager.CreateAsync(user, "123123aA@");

                    await _context.AppUsers.AddAsync(user);
                }

                if (!_context.Wallets.Any())
                {
                    var user = _context.AppUsers.Where(x => x.UserName == "admin").FirstOrDefault();

                    var wallet = new Wallet
                    {
                        DateCreated   = DateTime.Now,
                        PendingCoin   = 0,
                        Coin          = 999999999,
                        Id            = Guid.NewGuid().ToString(),
                        Status        = Status.Active,
                        PromotionCoin = 0,
                        WalletId      = TextHelper.RandomString(10),
                        UserId        = user.Id.ToString()
                    };

                    string walletId = wallet.WalletId;

                    await _context.Wallets.AddAsync(wallet);

                    _context.SaveChanges();

                    user.WalletId = walletId;
                    _context.AppUsers.Update(user);
                    _context.SaveChanges();
                }


                if (!_context.OwnerBanks.Any())
                {
                    var banks = new List <OwnerBank>
                    {
                        new OwnerBank {
                            FullNameOwner = "Adminstrator",
                            BankName      = "Ngân hàng ABC",
                            AccountNumber = "xxxx xxxx xxxx xxxx",
                            Branch        = "Chi nhánh VN",
                        },
                        new OwnerBank {
                            FullNameOwner = "Adminstrator",
                            BankName      = "Ngân hàng ABC 1",
                            AccountNumber = "xxxx xxxx xxxx xxxx",
                            Branch        = "Chi nhánh VN",
                        },
                        new OwnerBank {
                            FullNameOwner = "Adminstrator",
                            BankName      = "Ngân hàng ABC 2",
                            AccountNumber = "xxxx xxxx xxxx xxxx",
                            Branch        = "Chi nhánh VN",
                        }
                    };

                    _context.OwnerBanks.AddRange(banks);
                    _context.SaveChanges();
                }

                if (_context.Permissions.ToList().Count == 0)
                {
                    List <Permission> permissions = new List <Permission>();

                    var user = _context.Users.ToList()[0];
                    foreach (var fun in _context.Functions.ToList())
                    {
                        var per = new Permission()
                        {
                            Id = Guid.NewGuid().ToString(), DateCreated = DateTime.Now, Status = Status.Active, UserId = user.Id, FunctionId = fun.Id
                        };
                        permissions.Add(per);
                    }

                    await _context.Permissions.AddRangeAsync(permissions);
                }

                if (_context.Functions.ToList().Count == 0)
                {
                    List <Function> functions = new List <Function>()
                    {
                        new Function()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "Quyền Admin", Code = "ExportXLS", Status = Status.Active
                        },
                        new Function()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "Điều chỉnh tài khoản", Code = "Admin", Status = Status.Active
                        },
                        new Function()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "", Code = "Player", Status = Status.Active
                        },

                        new Function()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "", Code = "ProfitPercent.Read", Status = Status.Active
                        },
                        new Function()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "", Code = "ProfitPercent.Write", Status = Status.Active
                        },
                        new Function()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "", Code = "ProfitPercent.Delete", Status = Status.Active
                        },

                        new Function()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "", Code = "Account.Read", Status = Status.Active
                        },
                        new Function()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "", Code = "Account.Write", Status = Status.Active
                        },
                        new Function()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "", Code = "Account.Delete", Status = Status.Active
                        },

                        new Function()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "", Code = "Transaction.Read", Status = Status.Active
                        },
                        new Function()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "", Code = "Transaction.Write", Status = Status.Active
                        },
                        new Function()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "", Code = "Transaction.Delete", Status = Status.Active
                        },
                    };

                    await _context.Functions.AddRangeAsync(functions);

                    await _context.SaveChangesAsync();
                }

                if (_context.Brands.ToList().Count == 0)
                {
                    List <Brand> functions = new List <Brand>()
                    {
                        new Brand()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "Adidas", Status = Status.Active
                        },
                        new Brand()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "Puma", Status = Status.Active
                        },
                        new Brand()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "Nike", Status = Status.Active
                        },
                    };

                    await _context.Brands.AddRangeAsync(functions);

                    await _context.SaveChangesAsync();
                }

                if (_context.ProductCategories.ToList().Count == 0)
                {
                    var productCategories = new List <ProductCategory>()
                    {
                        new ProductCategory()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "Giày Adidas", Status = Status.Active
                        },
                        new ProductCategory()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "Giày Puma", Status = Status.Active
                        },
                        new ProductCategory()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "Giày Nike", Status = Status.Active
                        },
                        new ProductCategory()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "Áo thun", Status = Status.Active
                        },
                        new ProductCategory()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "Băng đeo tay", Status = Status.Active
                        },
                        new ProductCategory()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "Băng trán", Status = Status.Active
                        },
                        new ProductCategory()
                        {
                            Id = Guid.NewGuid().ToString(), Name = "Túi xách", Status = Status.Active
                        }
                    };

                    await _context.ProductCategories.AddRangeAsync(productCategories);

                    await _context.SaveChangesAsync();
                }

                if (_context.Products.ToList().Count == 0)
                {
                    var productCategory = _context.ProductCategories.FirstOrDefault();


                    var brand = _context.Brands.FirstOrDefault();
                    if (brand == null)
                    {
                        return(BadRequest());
                    }



                    if (productCategory == null)
                    {
                        return(BadRequest());
                    }
                    var products = new List <Product>()
                    {
                        new Product()
                        {
                            Id = Guid.NewGuid().ToString(), BrandId = brand.Id, ImageFile = "images/1.jpg", Name = "Sản phẩm 1", ProductCategoryId = productCategory.Id, Star = 5, Summary = "", Status = Status.Active, Price = 100000, UnitsInStock = 10
                        },
                        new Product()
                        {
                            Id = Guid.NewGuid().ToString(), BrandId = brand.Id, ImageFile = "images/2.jpg", Name = "Sản phẩm 2", ProductCategoryId = productCategory.Id, Star = 5, Summary = "", Status = Status.Active, Price = 100000, UnitsInStock = 10
                        },
                        new Product()
                        {
                            Id = Guid.NewGuid().ToString(), BrandId = brand.Id, ImageFile = "images/3.jpg", Name = "Sản phẩm 3", ProductCategoryId = productCategory.Id, Star = 5, Summary = "", Status = Status.Active, Price = 100000, UnitsInStock = 10
                        },
                        new Product()
                        {
                            Id = Guid.NewGuid().ToString(), BrandId = brand.Id, ImageFile = "images/4.jpg", Name = "Sản phẩm 4", ProductCategoryId = productCategory.Id, Star = 5, Summary = "", Status = Status.Active, Price = 100000, UnitsInStock = 10
                        },
                        new Product()
                        {
                            Id = Guid.NewGuid().ToString(), BrandId = brand.Id, ImageFile = "images/5.jpg", Name = "Sản phẩm 5", ProductCategoryId = productCategory.Id, Star = 5, Summary = "", Status = Status.Active, Price = 100000, UnitsInStock = 10
                        },
                        new Product()
                        {
                            Id = Guid.NewGuid().ToString(), BrandId = brand.Id, ImageFile = "images/6.jpg", Name = "Sản phẩm 6", ProductCategoryId = productCategory.Id, Star = 5, Summary = "", Status = Status.Active, Price = 100000, UnitsInStock = 10
                        },
                        new Product()
                        {
                            Id = Guid.NewGuid().ToString(), BrandId = brand.Id, ImageFile = "images/7.jpg", Name = "Sản phẩm 7", ProductCategoryId = productCategory.Id, Star = 5, Summary = "", Status = Status.Active, Price = 100000, UnitsInStock = 10
                        },
                        new Product()
                        {
                            Id = Guid.NewGuid().ToString(), BrandId = brand.Id, ImageFile = "images/8.jpg", Name = "Sản phẩm 8", ProductCategoryId = productCategory.Id, Star = 5, Summary = "", Status = Status.Active, Price = 100000, UnitsInStock = 10
                        },
                        new Product()
                        {
                            Id = Guid.NewGuid().ToString(), BrandId = brand.Id, ImageFile = "images/9.jpg", Name = "Sản phẩm 9", ProductCategoryId = productCategory.Id, Star = 5, Summary = "", Status = Status.Active, Price = 100000, UnitsInStock = 10
                        },
                        new Product()
                        {
                            Id = Guid.NewGuid().ToString(), BrandId = brand.Id, ImageFile = "images/10.jpg", Name = "Sản phẩm 10", ProductCategoryId = productCategory.Id, Star = 5, Summary = "", Status = Status.Active, Price = 100000, UnitsInStock = 10
                        },
                        new Product()
                        {
                            Id = Guid.NewGuid().ToString(), BrandId = brand.Id, ImageFile = "images/11.jpg", Name = "Sản phẩm 11", ProductCategoryId = productCategory.Id, Star = 5, Summary = "", Status = Status.Active, Price = 100000, UnitsInStock = 10
                        },
                    };
                    await _context.Products.AddRangeAsync(products);

                    await _context.SaveChangesAsync();
                }

                if (_context.Wishlists.ToList().Count == 0)
                {
                    var users     = _context.Users;
                    var wishlists = new List <Wishlist>();
                    foreach (var user in users)
                    {
                        var wishlist = new Wishlist();
                        wishlist.Id       = Guid.NewGuid().ToString();
                        wishlist.UserName = user.UserName;
                        wishlist.UserId   = user.Id;

                        wishlists.Add(wishlist);
                    }


                    await _context.Wishlists.AddRangeAsync(wishlists);

                    await _context.SaveChangesAsync();
                }



                await _context.SaveChangesAsync();

                return(Ok("Đã tạo được dữ liệu mẫu thành công"));
            }
            catch (Exception e)
            {
                return(BadRequest("Không tạo được dữ liệu mẫu"));
            }
        }
예제 #11
0
        public async Task <ActionResult <Object> > PostAppUser(AppUserViewModel appUserView)
        {
            try
            {
                if (EmailExits(appUserView.Email) || string.IsNullOrEmpty(appUserView.Email))
                {
                    return(BadRequest(new ResponseResult("Email đã tồn tại hoặc bị bỏ trống!")));
                }

                var user = new AppUser()
                {
                    DateOfBirth         = appUserView.DateOfBirth,
                    Email               = appUserView.Email,
                    FirstName           = appUserView.FirstName,
                    LastName            = appUserView.LastName,
                    UserName            = appUserView.UserName,
                    PhoneNumber         = appUserView.PhoneNumber,
                    Avatar              = appUserView.Avatar,
                    NickName            = appUserView.NickName,
                    TransactionPassword = appUserView.TransactionPassword,
                    Id = Guid.NewGuid()
                };

                if (!string.IsNullOrEmpty(appUserView.RootUserId))
                {
                    // generate link ref
                    var rootUser = _context.AppUsers.Where(x => x.Id.ToString() == appUserView.RootUserId).FirstOrDefault();
                    if (rootUser != null)
                    {
                        user.RootUserId      = rootUser.Id;
                        user.RefRegisterLink = DomainConsts.LotteryDomain + "/api/Users/register/" + user.Id.ToString();
                    }
                }


                // create wallet
                var wallet = new Wallet
                {
                    DateCreated   = DateTime.Now,
                    Coin          = 0,
                    PendingCoin   = 0,
                    PromotionCoin = 0,
                    Status        = Status.Active,
                    WalletId      = TextHelper.RandomString(10),
                    Id            = Guid.NewGuid().ToString(),
                    UserId        = ""
                };

                _context.Wallets.Add(wallet);

                await _context.SaveChangesAsync();

                var newWallet = _context.Wallets.Where(x => string.IsNullOrEmpty(x.UserId)).FirstOrDefault();

                user.WalletId = newWallet.WalletId;


                var result = await _userManager.CreateAsync(user, appUserView.Password);

                if (result.Succeeded)
                {
                    newWallet.UserId = user.Id.ToString();

                    await _context.SaveChangesAsync();

                    var createdUser = await _context.AppUsers.Where(x => x.Id == user.Id).FirstOrDefaultAsync();

                    var createdUserView = Mapper.Map <AppUser, AppUserViewModel>(createdUser);
                    return(createdUserView);

                    ;
                }
                else
                {
                    _context.Wallets.Remove(newWallet);
                    await _context.SaveChangesAsync();

                    string error = "";
                    foreach (var e in result.Errors)
                    {
                        error += e.Description;
                    }
                    return(BadRequest(new ResponseResult(error)));
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                throw new DbUpdateConcurrencyException("Lỗi hệ thống!");
            }
            catch (Exception)
            {
                throw new Exception();
            }
        }