Esempio n. 1
0
        public async Task <ActionResult> Remove(int id)
        {
            using (var db = new OnlineShopDbContext())
            {
                var currentInvoiceItems = await db.InvoiceItems.Where(x => x.Invoice.UserId == CurrentUserId).ToListAsync();

                if (currentInvoiceItems.Where(x => x.ItemId == id).Select(x => x.Count).FirstOrDefault() > 1)
                {
                    var currentInvoiceItem = currentInvoiceItems.Where(x => x.ItemId == id).FirstOrDefault();
                    currentInvoiceItem.Count--;
                    currentInvoiceItem.TotalPrice     = (currentInvoiceItem.Count * currentInvoiceItem.EachItemPrice);
                    currentInvoiceItem.SubmissionDate = DateTime.Now;
                    await db.SaveChangesAsync();
                }
                else
                {
                    var invoiceItem = await db.InvoiceItems.Where(x => x.Invoice.UserId == CurrentUserId && x.ItemId == id).FirstOrDefaultAsync();

                    db.InvoiceItems.Remove(invoiceItem);
                    await db.SaveChangesAsync();
                }
                await UpdatePrice(currentInvoiceItems.Select(x => x.InvoiceId).FirstOrDefault());
            }
            return(null);
        }
Esempio n. 2
0
 public async Task Do(CategoryVMUI vm)
 {
     _context.Categories.Add(new Category
     {
         CategoryId = vm.CategoryId,
         Name       = vm.Name,
         Photo      = vm.Photo,
     });
     await _context.SaveChangesAsync();
 }
Esempio n. 3
0
        public async Task <ActionResult> Add(int id, int count)
        {
            using (var db = new OnlineShopDbContext())
            {
                int invoiceId;
                var currentInvoice = await db.Invoices.Where(x => x.UserId == CurrentUserId).FirstOrDefaultAsync();

                if (currentInvoice == null)
                {
                    var invoice = new Invoice()
                    {
                        UserId         = CurrentUserId,
                        InvoiceStateId = 1,
                        InvoiceSum     = 0,
                        SubmissionDate = DateTime.Now
                    };
                    db.Invoices.Add(invoice);
                    await db.SaveChangesAsync();

                    invoiceId = invoice.Id;
                }
                else
                {
                    invoiceId = currentInvoice.Id;
                }
                var currentInvoiceItems = await db.InvoiceItems.Where(x => x.InvoiceId == invoiceId).ToListAsync();

                if (currentInvoiceItems.Any(x => x.ItemId == id))
                {
                    var currentInvoiceItem = currentInvoiceItems.Where(x => x.ItemId == id).FirstOrDefault();
                    currentInvoiceItem.Count          = count;
                    currentInvoiceItem.TotalPrice     = (currentInvoiceItem.Count * currentInvoiceItem.EachItemPrice);
                    currentInvoiceItem.SubmissionDate = DateTime.Now;
                    await db.SaveChangesAsync();
                }
                else
                {
                    var item = await db.Items.FindAsync(id);

                    var invoiceItem = new InvoiceItem()
                    {
                        InvoiceId      = invoiceId,
                        ItemId         = id,
                        SubmissionDate = DateTime.Now,
                        Count          = count,
                        EachItemPrice  = item.Price,
                        TotalPrice     = item.Price,
                    };
                    db.InvoiceItems.Add(invoiceItem);
                    await db.SaveChangesAsync();
                }
                await UpdatePrice(invoiceId);
            }
            return(null);
        }
        public async Task Do(CategoryVMUI vm)
        {
            var category = new Category
            {
                CategoryId = vm.CategoryId,
                Name       = vm.Name,
                Photo      = vm.Photo,
            };

            _context.Categories.Update(category);
            await _context.SaveChangesAsync();
        }
        public async Task <int> CreateAsync(string name)
        {
            Category category = new Category
            {
                Name      = name,
                CreatedOn = dateTimeProvider.UtcNow()
            };

            db.Add(category);

            await db.SaveChangesAsync();

            return(category.Id);
        }
Esempio n. 6
0
        public async Task <int> ChangeOrder(int OrderID, int?StatusID)
        {
            try
            {
                var order = db.ORDERs.Find(OrderID);
                order.OrderStatusID = StatusID;
                await db.SaveChangesAsync();

                return(OrderID);
            }
            catch
            {
                return(0);
            }
        }
Esempio n. 7
0
        public async Task <bool> DeleteCustomer(int ID)
        {
            try
            {
                var cus = await db.CUSTOMERs.Where(x => x.CustomerID == ID).SingleOrDefaultAsync();

                db.CUSTOMERs.Remove(cus);
                await db.SaveChangesAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public async Task Do(ProductVMUI vm)
        {
            var product = new Product
            {
                ProductId     = vm.ProductId,
                Name          = vm.Name,
                Description   = vm.Description,
                Stock         = vm.Stock,
                Price         = vm.Price,
                Photo         = vm.Photo,
                CategoryRefId = vm.CategoryRefId,
            };

            _context.Products.Update(product);
            await _context.SaveChangesAsync();
        }
        public async Task <int> Delete(int productId)
        {
            var del = _context.Categories.Find(productId);

            _context.Categories.Remove(del);
            return(await _context.SaveChangesAsync());
        }
Esempio n. 10
0
        public async Task <long> Insert(Content entity)
        {
            db.Contents.Add(entity);
            await db.SaveChangesAsync();

            return(entity.ID);
        }
Esempio n. 11
0
        public async Task <ActionResult> Signup(CreateUserViewModel model)
        {
            using (var db = new OnlineShopDbContext())
            {
                var newUser = new User
                {
                    Email    = model.Email,
                    Fullname = model.Fullname,
                    Password = model.Password,
                    Mobile   = model.Mobile,
                    RoleId   = 1 //normal user
                    ,
                    IsVerified = false,
                    IsReviewed = false
                };
                db.Users.Add(newUser);
                await db.SaveChangesAsync();

                //RoleViewModel roleModel = new RoleViewModel { RoleId = 1, UserId = newUser.Id };
                //FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
                //   newUser.Fullname,
                //   DateTime.Now,
                //   DateTime.Now.AddMinutes(30),
                //   false,
                //   JsonConvert.SerializeObject(roleModel),
                //   FormsAuthentication.FormsCookiePath);
                //string encTicket = FormsAuthentication.Encrypt(ticket);
                //Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
                return(Redirect("/account/pending"));
            }
        }
Esempio n. 12
0
 public virtual async Task <bool> SaveChangesAsync()
 {
     if (await context.SaveChangesAsync() > 0)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 13
0
        public async Task CreateAsync(string title, string shortDescription, string longDescription, decimal price, ICollection <Image> images, string thumbnail, int categoryId)
        {
            Product product = new Product
            {
                Title            = title,
                ShortDescription = shortDescription,
                LongDescription  = longDescription,
                Price            = price,
                Images           = images,
                Thumbnail        = thumbnail,
                CreatedOn        = dateTimeProvider.UtcNow(),
                CategoryId       = categoryId
            };

            await db.Products.AddAsync(product);

            await db.SaveChangesAsync();
        }
Esempio n. 14
0
 public async Task Do(ProductInOrdersViewModel vm)
 {
     _context.ProductInOrders.Add(new ProductInOrder
     {
         OrderRefId   = vm.OrderRefId,
         ProductRefId = vm.ProductRefId,
         UsedQuantity = vm.UsedQuantity,
     });
     await _context.SaveChangesAsync();
 }
Esempio n. 15
0
        public async Task <bool> CreateProductDetail(string productID, List <string> sizeID)
        {
            try
            {
                foreach (var item in sizeID)
                {
                    _ = db.PRODUCTDETAILs.Add(new PRODUCTDETAIL {
                        ProductID = productID, SizeID = int.Parse(item)
                    });
                }
                await db.SaveChangesAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 16
0
 public async Task Do(CartItemsViewModel vm)
 {
     _context.CartItems.Add(new CartItems
     {
         CartRefId    = vm.CartRefId,
         ProductRefId = vm.ProductRefId,
         Quantity     = vm.Quantity,
     });
     await _context.SaveChangesAsync();
 }
        public async Task Do(int cartId, int productId)
        {
            var cartItem = new CartItems
            {
                CartRefId    = cartId,
                ProductRefId = productId,
            };

            _context.CartItems.Remove(cartItem);
            await _context.SaveChangesAsync();
        }
        public async Task Do(int orderId, int productId)
        {
            var productInOrder = new ProductInOrder
            {
                OrderRefId   = orderId,
                ProductRefId = productId,
            };

            _context.ProductInOrders.Remove(productInOrder);
            await _context.SaveChangesAsync();
        }
Esempio n. 19
0
        public async Task UpdatePrice(int id)
        {
            using (var db = new OnlineShopDbContext())
            {
                var invoice = await db.Invoices.FindAsync(id);

                invoice.InvoiceSum = await db.InvoiceItems.Where(x => x.InvoiceId == id).Select(x => x.TotalPrice).DefaultIfEmpty(0).SumAsync(x => x);

                await db.SaveChangesAsync();
            }
        }
Esempio n. 20
0
        public async Task Trash(int id)
        {
            using (var db = new OnlineShopDbContext())
            {
                var invoiceItem = await db.InvoiceItems.Where(x => x.Invoice.UserId == CurrentUserId && x.ItemId == id).FirstOrDefaultAsync();

                var invoiceId = invoiceItem.InvoiceId;
                db.InvoiceItems.Remove(invoiceItem);
                await db.SaveChangesAsync();
                await UpdatePrice(invoiceId);
            }
        }
        public async Task Do(ProductInOrdersViewModel vm)
        {
            var productInOrder = new ProductInOrder
            {
                OrderRefId   = vm.OrderRefId,
                ProductRefId = vm.ProductRefId,
                UsedQuantity = vm.UsedQuantity,
            };

            _context.ProductInOrders.Update(productInOrder);
            await _context.SaveChangesAsync();
        }
        public async Task Do(int categoryId)
        {
            var category = _context.Categories
                           .FirstOrDefault(categ => categ.CategoryId == categoryId);

            _context.Categories.Remove(category);
            if (!string.IsNullOrEmpty(category.Photo))
            {
                _fileManager.RemoveImage(category.Photo, "CategoryPhoto");
            }
            await _context.SaveChangesAsync();
        }
        public async Task Do(int productId)
        {
            var product = _context.Products
                          .FirstOrDefault(product => product.ProductId == productId);

            _context.Products.Remove(product);
            if (!string.IsNullOrEmpty(product.Photo))
            {
                _fileManager.RemoveImage(product.Photo, "ProductPhoto");
            }
            await _context.SaveChangesAsync();
        }
        public async Task Do(CartItemsViewModel vm)
        {
            var cartItems = new CartItems
            {
                CartRefId    = vm.CartRefId,
                ProductRefId = vm.ProductRefId,
                Quantity     = vm.Quantity,
            };

            _context.CartItems.Update(cartItems);
            await _context.SaveChangesAsync();
        }
Esempio n. 25
0
 public async Task Do(OrderViewModel vm)
 {
     _context.Orders.Add(new Order
     {
         OrderId      = vm.OrderId,
         Status       = vm.Status,
         CustomerId   = vm.CustomerId,
         TotalOrdered = vm.TotalOrdered,
         Created      = DateTime.Now,
     });
     await _context.SaveChangesAsync();
 }
Esempio n. 26
0
 public async Task Do(ShoppingCartViewModel vm)
 {
     _context.ShoppingCarts.Add(new ShoppingCart
     {
         CartId      = vm.CartId,
         Status      = "Active",
         CustomerId  = vm.CustomerId,
         TotalInCart = vm.TotalInCart,
         Created     = vm.Created,
     });
     await _context.SaveChangesAsync();
 }
 public async Task Do(OrderInfosViewModel vm)
 {
     _context.OrdersInfos.Add(new OrderInfo
     {
         OrderInfoId = vm.OrderInfoId,
         FirstName   = vm.FirstName,
         LastName    = vm.LastName,
         Address     = vm.Address,
         PhoneNo     = vm.PhoneNo,
         OrderRefId  = vm.OrderRefId,
     });
     await _context.SaveChangesAsync();
 }
        public async Task Do(ShoppingCartViewModel vm)
        {
            var cart = new ShoppingCart
            {
                CartId      = vm.CartId,
                Status      = vm.Status,
                CustomerId  = vm.CustomerId,
                TotalInCart = vm.TotalInCart,
                Created     = vm.Created,
            };

            _context.ShoppingCarts.Update(cart);
            await _context.SaveChangesAsync();
        }
Esempio n. 29
0
        public async Task <string> CreateProduct(PRODUCT prod)
        {
            var product = new PRODUCT()
            {
                ViewCount      = 0,
                ProductID      = prod.ProductID,
                ProductName    = prod.ProductName,
                ProductPrice   = prod.ProductPrice,
                PromotionPrice = prod.PromotionPrice,
                ProductStock   = prod.ProductStock,
                CategoryID     = prod.CategoryID,
                MetaKeyword    = prod.ProductName,
                ShowImage_1    = prod.ShowImage_1,
                ShowImage_2    = prod.ShowImage_2,
                ProductStatus  = prod.ProductStatus,
                CreatedDate    = DateTime.Now
            };

            db.PRODUCTs.Add(product);
            await db.SaveChangesAsync();

            return(product.ProductID);
        }
        public async Task <int> AddImages(int productId, ProductImageCreateRequest request)
        {
            var productImage = new ProductImage()
            {
                ProductId   = productId,
                SortOrder   = request.SortOrder,
                DateCreated = DateTime.Now,
                Caption     = request.Caption
            };

            if (request.ImageFile != null)
            {
                productImage.ImagePath = await this.SaveFile(request.ImageFile);

                productImage.FileSize = request.ImageFile.Length;
            }
            _context.ProductImages.Add(productImage);
            await _context.SaveChangesAsync();

            return(productImage.Id);
        }