public ProductView GetProduct(int id) { using (var onlineShopContext = new OnlineShopWebEntities()) { return(AutoMapper.Mapper.Map <Product, ProductView>(onlineShopContext.Product.Where(x => x.Id == id).FirstOrDefault())); } }
public IEnumerable <OrderView> GetUserOrders(string userId) { using (var onlineShopContext = new OnlineShopWebEntities()) { return(AutoMapper.Mapper.Map <IEnumerable <Order>, IEnumerable <OrderView> >(onlineShopContext.Order.Where(x => x.AspNetUserId == userId))); } }
public IEnumerable <CategoryView> GetCategories() { using (var onlineShopContext = new OnlineShopWebEntities()) { return(AutoMapper.Mapper.Map <IEnumerable <Category>, IEnumerable <CategoryView> >(onlineShopContext.Category)); } }
public IEnumerable <ProductView> GetProducts() { using (var onlineShopContext = new OnlineShopWebEntities()) { return(AutoMapper.Mapper.Map <IEnumerable <Product>, IEnumerable <ProductView> >(onlineShopContext.Product)); } }
public IEnumerable <ProductReviewView> GetProductReviews(int id) { using (var onlineShopContext = new OnlineShopWebEntities()) { return(AutoMapper.Mapper.Map <IEnumerable <ProductReview>, IEnumerable <ProductReviewView> >(onlineShopContext.ProductReview.Where(x => x.ProductId == id))); } }
public ProductView GetProductById(int id) { using (var onlineShopContext = new OnlineShopWebEntities()) { var Product = onlineShopContext.Product.Find(id); return(AutoMapper.Mapper.Map <Product, ProductView>(Product)); } }
public CategoryView GetCategoryById(int id) { using (var onlineShopContext = new OnlineShopWebEntities()) { var category = onlineShopContext.Category.Find(id); return(AutoMapper.Mapper.Map <Category, CategoryView>(category)); } }
public IEnumerable <CartView> GetCartProduct(string userId) { using (var onlineShopContext = new OnlineShopWebEntities()) { var carts = onlineShopContext.Cart.Include(x => x.Product.Category).Where(x => x.AspNetUserId == userId); return(AutoMapper.Mapper.Map <IEnumerable <Cart>, IEnumerable <CartView> >(carts)); } }
public async Task RemoveAllCart(string userId) { using (var onlineShopContext = new OnlineShopWebEntities()) { var carts = onlineShopContext.Cart.Where(x => x.AspNetUserId == userId); onlineShopContext.Cart.RemoveRange(carts); await onlineShopContext.SaveChangesAsync(); } }
private void AddProduct(ProductView Product) { var ProductAdd = AutoMapper.Mapper.Map <ProductView, Product>(Product); using (var onlineShopContext = new OnlineShopWebEntities()) { onlineShopContext.Product.Add(ProductAdd); onlineShopContext.SaveChanges(); } }
private void AddCategory(CategoryView category) { var categoryAdd = AutoMapper.Mapper.Map <CategoryView, Category>(category); using (var onlineShopContext = new OnlineShopWebEntities()) { onlineShopContext.Category.Add(categoryAdd); onlineShopContext.SaveChanges(); } }
public void AddProductReview(ProductReviewView productReviewView) { var productReview = AutoMapper.Mapper.Map <ProductReviewView, ProductReview>(productReviewView); using (var onlineShopContext = new OnlineShopWebEntities()) { productReview.ReviewDate = DateTime.Now; onlineShopContext.ProductReview.Add(productReview); onlineShopContext.SaveChanges(); } }
public void RemoveProduct(int id) { using (var onlineShopContext = new OnlineShopWebEntities()) { var Product = onlineShopContext.Product.Find(id); if (Product != null) { onlineShopContext.Product.Remove(Product); onlineShopContext.SaveChanges(); } } }
public async Task RemoveFromCart(int id) { using (var onlineShopContext = new OnlineShopWebEntities()) { Cart cart = onlineShopContext.Cart.Where(x => x.ProductId == id).FirstOrDefault(); if (cart != null) { onlineShopContext.Cart.Remove(cart); await onlineShopContext.SaveChangesAsync(); } } }
public void RemoveCategory(int id) { using (var onlineShopContext = new OnlineShopWebEntities()) { var category = onlineShopContext.Category.Find(id); if (category != null) { onlineShopContext.Category.Remove(category); onlineShopContext.SaveChanges(); } } }
public void CheckoutOrder(OrderView order) { using (var onlineShopContext = new OnlineShopWebEntities()) { var newOrder = AutoMapper.Mapper.Map <OrderView, Order>(order); var product = onlineShopContext.Product.Where(x => x.Id == order.TargetId).FirstOrDefault(); newOrder.OrderDetails.Add(new OrderDetail { Product = product, Quantity = 1, UnitPrice = product.Price }); onlineShopContext.Order.Add(newOrder); onlineShopContext.SaveChanges(); } }
public CatalogResult GetCatalog(int pageSize, string search = null, int page = 0, int?category = null) { CatalogResult catalogPager = new CatalogResult(); using (var onlineShopContext = new OnlineShopWebEntities()) { var products = onlineShopContext.Product.Where(x => (category == null || x.CategoryId == category) && (search == null || x.Name.Contains(search))).OrderBy(x => x.Id); catalogPager.MoreResults = products.Count() - (pageSize * (page + 1)); var pageProducts = products.Skip(pageSize * page).Take(pageSize); catalogPager.Products = AutoMapper.Mapper.Map <IEnumerable <Product>, IEnumerable <ProductView> >(pageProducts); } return(catalogPager); }
private void UpdateProduct(ProductView Product) { var ProductUpdate = AutoMapper.Mapper.Map <ProductView, Product>(Product); using (var onlineShopContext = new OnlineShopWebEntities()) { var ProductOriginal = onlineShopContext.Product.Find(Product.Id); if (Product != null) { onlineShopContext.Entry(ProductOriginal).CurrentValues.SetValues(ProductUpdate); onlineShopContext.SaveChanges(); } } }
private void UpdateCategory(CategoryView category) { var categoryUpdate = AutoMapper.Mapper.Map <CategoryView, Category>(category); using (var onlineShopContext = new OnlineShopWebEntities()) { var categoryOriginal = onlineShopContext.Category.Find(category.Id); if (category != null) { onlineShopContext.Entry(categoryOriginal).CurrentValues.SetValues(categoryUpdate); onlineShopContext.SaveChanges(); } } }
public OrderView GetOrderReview(int targetId) { OrderView order = new OrderView { TargetId = targetId, OrderType = Enums.OrderTypeEnum.SingleProduct, OrderTypeInt = (int)Enums.OrderTypeEnum.SingleProduct, OrderStatusId = 1 }; using (var onlineShopContext = new OnlineShopWebEntities()) { var product = AutoMapper.Mapper.Map <Product, ProductView>(onlineShopContext.Product.Where(x => x.Id == targetId).FirstOrDefault()); order.OrderDetails.Add(new OrderDetailView { Product = product, Quantity = 1 }); } return(order); }
public void CheckoutOrder(OrderView order) { using (var onlineShopContext = new OnlineShopWebEntities()) { var newOrder = AutoMapper.Mapper.Map <OrderView, Order>(order); var carts = onlineShopContext.Cart.Where(x => x.AspNetUserId == order.AspNetUserId); foreach (var cart in carts) { newOrder.OrderDetails.Add(new OrderDetail { Product = cart.Product, Quantity = cart.Quantity, UnitPrice = cart.Product.Price }); } onlineShopContext.Order.Add(newOrder); onlineShopContext.Cart.RemoveRange(carts); onlineShopContext.SaveChanges(); } }
public OrderView GetOrderReview(int targetId) { OrderView order = new OrderView { TargetId = targetId, OrderType = Enums.OrderTypeEnum.AllCart, OrderTypeInt = (int)Enums.OrderTypeEnum.AllCart, OrderStatusId = 1 }; if (HttpContext.Current != null) { var userId = HttpContext.Current.User.Identity.GetUserId(); using (var onlineShopContext = new OnlineShopWebEntities()) { var carts = onlineShopContext.Cart.Where(x => x.AspNetUserId == userId).ToList(); order.OrderDetails = carts.Select(x => new OrderDetailView { Product = AutoMapper.Mapper.Map <Product, ProductView>(x.Product), Quantity = x.Quantity }).ToList(); } } return(order); }
public void AddToCart(int id, string userId) { using (var onlineShopContext = new OnlineShopWebEntities()) { Cart cart = onlineShopContext.Cart.Where(x => x.AspNetUserId == userId && x.ProductId == id).FirstOrDefault(); if (cart == null) { cart = new Cart { AspNetUserId = userId, ProductId = id, Quantity = 1, DateCreated = DateTime.Now }; onlineShopContext.Cart.Add(cart); } else { cart.Quantity++; } onlineShopContext.SaveChanges(); } }