Example #1
0
        public async Task <int> Create(OrderCreateRequest request)
        {
            var tempUser = await _context.Users.FindAsync(request.UserId);

            var tempCartList = await _context.Carts.Where(x => x.UserId == request.UserId).ToListAsync();

            var newOrder = new Order()
            {
                OrderDate       = DateTime.Now,
                ShipAddress     = tempUser.Address + " " + tempUser.City + " " + tempUser.State,
                ShipName        = tempUser.FirstName + " " + tempUser.LastName,
                ShipEmail       = tempUser.Email,
                ShipPhoneNumber = tempUser.PhoneNumber,
                UserId          = tempUser.Id,
                Status          = Data.Enums.OrderStatus.InProgress,
                OrderDetails    = new List <OrderDetail>(),
            };

            for (var i = 0; i < tempCartList.Count; i++)
            {
                var newOrderDetail = new OrderDetail()
                {
                    ItemId   = tempCartList[i].ItemId,
                    Quantity = tempCartList[i].Quantity,
                    Price    = tempCartList[i].Price,
                };
                await _context.OrderDetails.AddAsync(newOrderDetail);

                _context.Carts.Remove(tempCartList[i]);
                newOrder.OrderDetails.Add(newOrderDetail);
            }
            await _context.Orders.AddAsync(newOrder);

            return(await _context.SaveChangesAsync());
        }
Example #2
0
        public async Task <int> AddNewCart(CartViewModel newCart)
        {
            var temp     = _context.Carts.Where(x => x.UserId == newCart.UserId && x.ItemId == newCart.ItemId).ToList();
            var quantity = 1;

            if (temp.Count != 0)
            {
                for (var i = 0; i < temp.Count; i++)
                {
                    if (temp[i].ItemId == newCart.ItemId)
                    {
                        var itemPrice = _context.Items.Find(newCart.ItemId).TotalMaking;
                        temp[i].Quantity += quantity;
                        temp[i].Price     = itemPrice * temp[i].Quantity;
                    }
                }
            }
            else
            {
                var item = await _context.Items.FindAsync(newCart.ItemId);

                var newCartTemp = new Cart()
                {
                    ItemId      = newCart.ItemId,
                    Quantity    = quantity,
                    Price       = item.TotalMaking,
                    UserId      = newCart.UserId,
                    DateCreated = DateTime.Now,
                };
                _context.Carts.Add(newCartTemp);
            }

            return(await _context.SaveChangesAsync());
        }
Example #3
0
 public async Task<int> Create(DiamondCreateRequest request)
 {
     var diamond = new Diamond()
     {
         DiamondShape = request.DiamondShape,
         Price = request.Price
     };
     _context.Diamonds.Add(diamond);
     await _context.SaveChangesAsync();
     return diamond.Id;
 }
Example #4
0
        public async Task <int> Create(CategoryCreateRequest newCategory)
        {
            var category = new Category()
            {
                Name = newCategory.Name
            };

            _context.Categories.Add(category);
            await _context.SaveChangesAsync();

            return(category.Id);
        }
Example #5
0
        public async Task <int> Create(RingSizeCreateRequest request)
        {
            var temp = new RingSize()
            {
                SizeNumber = request.SizeNumber
            };

            _context.RingSizes.Add(temp);
            await _context.SaveChangesAsync();

            return(temp.Id);
        }
Example #6
0
        public async Task <int> Create(ProductTypeCreateRequest request)
        {
            var temp = new ProductType()
            {
                Name = request.Name,
            };

            _context.ProductTypes.Add(temp);
            await _context.SaveChangesAsync();

            return(temp.Id);
        }
Example #7
0
        public async Task <int> Create(GoldCreateRequest request)
        {
            var gold = new Gold()
            {
                GoldCarat = request.GoldCarat,
                Price     = request.Price
            };

            _context.Golds.Add(gold);
            await _context.SaveChangesAsync();

            return(gold.Id);
        }
Example #8
0
        public async Task <int> Create(CertificationCreateRequest request)
        {
            var certification = new Certification()
            {
                Name    = request.Name,
                LinkUrl = request.LinkUrl
            };

            _context.Certifications.Add(certification);
            await _context.SaveChangesAsync();

            return(certification.Id);
        }
Example #9
0
        public async Task <bool> changPass(User user)
        {
            if (user != null)
            {
                var u = await db.Users.FindAsync(user.Id);

                u.Password = user.Password;
                db.Users.Update(u);
                await db.SaveChangesAsync();

                return(true);
            }
            return(false);
        }