public int AddGallary(IFormFile galleryImg, int productId) { ProductGallery productGallery = new ProductGallery(); productGallery.CreatDate = DateTime.Now; productGallery.ImageName = "no-photo.jpg"; productGallery.ProductId = productId; if (galleryImg != null && galleryImg.IsImage()) { productGallery.ImageName = NameGenerator.GenerateUniqCode() + Path.GetExtension(galleryImg.FileName); string imagePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/ProductGallary", productGallery.ImageName); using (var stream = new FileStream(imagePath, FileMode.Create)) { galleryImg.CopyTo(stream); } ImageConvertor imgResizer = new ImageConvertor(); string thumbPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/ProductGallary/thumb", productGallery.ImageName); imgResizer.Image_resize(imagePath, thumbPath, 200); } _context.productGalleries.Add(productGallery); _context.SaveChanges(); return(productGallery.GalleryId); }
public int AddOrder(int ProductId, string userNumber, int sizeId, int colorId, int quantityNumber) { User user = _userService.GetUserByNumber(userNumber); Order order = _context.Orders.FirstOrDefault(p => !p.IsFinaly); Product product = _context.Products.Find(ProductId); string colorName = _productService.GetColorNameById(colorId); string sizeName = _productService.GetSizeNameById(sizeId); if (order == null) { order = new Order() { IsFinaly = false, CreateDate = DateTime.Now, OrderSum = product.Price, UserId = user.UserId, OrderType = OrderType.TakingOrders, OrderDetails = new List <OrderDetail>() { new OrderDetail() { ProductId = product.Id, Count = quantityNumber, Price = product.Price, SizeId = sizeId, ColorId = colorId, ColorName = colorName, SizeName = sizeName } } }; _context.Orders.Add(order); _context.SaveChanges(); } else { OrderDetail detail = _context.OrderDetails .FirstOrDefault(o => o.OrderId == order.OrderId && o.ProductId == product.Id); if (detail != null && detail.ColorId == colorId && detail.SizeId == sizeId) { detail.Count += quantityNumber; _context.OrderDetails.Update(detail); } else { detail = new OrderDetail() { OrderId = order.OrderId, Count = quantityNumber, ProductId = product.Id, Price = product.Price, SizeId = sizeId, ColorId = colorId, ColorName = colorName, SizeName = sizeName }; _context.OrderDetails.Add(detail); } _context.SaveChanges(); } UpdatePriceOrder(order.OrderId); return(order.OrderId); }
public int AddUser(User user) { _context.Users.Add(user); _context.SaveChanges(); return(user.UserId); }