Exemplo n.º 1
0
        public int AddShop(Shop shop, IFormFile imgShop)
        {
            shop.ImageName = "no-photo.jpg";

            if (imgShop != null && imgShop.IsImage())
            {
                shop.ImageName = NameGenerator.GenerateUniqCode() + Path.GetExtension(imgShop.FileName);
                string imagePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/shop", shop.ImageName);

                using (var stream = new FileStream(imagePath, FileMode.Create))
                {
                    imgShop.CopyTo(stream);
                }
            }
            _context.Shops.Add(shop);
            _context.SaveChanges();
            return(shop.ShopId);
        }
Exemplo n.º 2
0
        public int AddOrder(string userName, int productId)
        {
            int userId = _userService.GetUserIdByUserName(userName);

            Order order = _context.Orders
                          .FirstOrDefault(o => o.UserId == userId && !o.IsFinaly);

            var product = _context.Product.Find(productId);

            if (order == null)
            {
                order = new Order()
                {
                    UserId       = userId,
                    IsFinaly     = false,
                    CreateDate   = DateTime.Now,
                    OrderSum     = product.ProductPrice,
                    OrderDetails = new List <OrderDetail>()
                    {
                        new OrderDetail()
                        {
                            ProductId = productId,
                            Count     = 1,
                            Price     = product.ProductPrice
                        }
                    }
                };
                _context.Orders.Add(order);
                _context.SaveChanges();
            }
            else
            {
                OrderDetail detail = _context.OrderDetails
                                     .FirstOrDefault(d => d.OrderId == order.OrderId && d.ProductId == productId);
                if (detail != null)
                {
                    detail.Count += 1;
                    _context.OrderDetails.Update(detail);
                }
                else
                {
                    detail = new OrderDetail()
                    {
                        OrderId   = order.OrderId,
                        Count     = 1,
                        ProductId = productId,
                        Price     = product.ProductPrice,
                    };
                    _context.OrderDetails.Add(detail);
                }

                _context.SaveChanges();
                UpdatePriceOrder(order.OrderId);
            }


            return(order.OrderId);
        }
Exemplo n.º 3
0
        public int AddProduct(Product product, IFormFile imgProduct)
        {
            product.ProductImageName = "no-photo.jpg";
            if (imgProduct != null && imgProduct.IsImage())
            {
                product.ProductImageName = NameGenerator.GenerateUniqCode() + Path.GetExtension(imgProduct.FileName);
                string imagePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/product/image", product.ProductImageName);

                using (var stream = new FileStream(imagePath, FileMode.Create))
                {
                    imgProduct.CopyTo(stream);
                }
                // ImageConvertor imgResizer = new ImageConvertor();
                // string thumbPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/product/thumb", product.ProductImageName);
                //
                // imgResizer.Image_resize(imagePath, thumbPath, 225);
            }

            _context.Add(product);
            _context.SaveChanges();

            return(product.ProductId);
        }
 public int AddRole(Role role)
 {
     _context.CakeshopRoles.Add(role);
     _context.SaveChanges();
     return(role.RoleId);
 }
Exemplo n.º 5
0
 public int AddUser(User user)
 {
     _context.CakeshopUsers.Add(user);
     _context.SaveChanges();
     return(user.UserId);
 }