public ReturnEvent GetMostRecentReturn()
 {
     using (var db = new ShopDataContext())
     {
         return(db.ReturnEvents.Select(p => p).ToList().LastOrDefault());
     }
 }
 public List <ReturnEvent> GetReturnEventsByProductId(int id)
 {
     using (var db = new ShopDataContext())
     {
         return(db.ReturnEvents.Where(ev => ev.ProductId.Equals(id)).ToList());
     }
 }
예제 #3
0
 public Product GetProductByName(string name)
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         return(db.Products.FirstOrDefault(product => product.product_name.Equals(name)));
     }
 }
 public List <ReturnEvent> GetAllReturnEvents()
 {
     using (var db = new ShopDataContext())
     {
         return(db.ReturnEvents.Select(ev => ev).ToList());
     }
 }
예제 #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ClientScript.RegisterStartupScript(GetType(), "hwa", "getTweets();", true);
        //create customer if customer does not exist in session
        try
        {
            if (HttpContext.Current.Session["Customer"] == null)
            {
                Customer aCustomer;
                aCustomer           = CartFunctions.createCustomer();
                Session["Customer"] = aCustomer;
            } //end if
        }     //end try
        catch (Exception)
        {
        }//end catch

        try
        {
            //check to see if user is logged on, if so assigns user id to CUSTID in customer object
            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
                string   custID;
                Customer aCustomer = (Customer)Session["Customer"];

                MembershipUser user = Membership.GetUser();
                custID           = user.ProviderUserKey.ToString();
                aCustomer.CUSTID = custID;
            } //end if
        }     //end try
        catch (Exception)
        {
        }//end catch

        try
        {
            //getWeather();
        }//end try
        catch (Exception)
        {
        }//end catch

        try
        {
            //if its a new session get products list from database and add it so session variable
            if (Session.IsNewSession)
            {
                ShopDataContext dc = new ShopDataContext();

                da = new DataAccess();
                List <Product> p = da.getProducts();
                Session["Products"] = p;
            } //endif
        }     //end try
        catch (Exception)
        {
        }//end catch

        getLatestProducts();
    }
예제 #6
0
 public Product GetLastProduct()
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         return(db.Products.Select(product => product).ToList().LastOrDefault());
     }
 }
        public void SaveChanges(DataGridView gridView, string cashier, string salesid, string status, string customer, decimal discount, decimal total, decimal subtotal, string items)
        {
            SalesModel model    = new SalesModel();
            int        rowindex = gridView.CurrentRow.Index;

            ShopDataContext db = new ShopDataContext();


            db.Sales.InsertOnSubmit(
                new Sale
            {
                SalesNumber  = salesid,
                CashierId    = cashier,
                Salesdate    = DateTime.Now,
                Subtotal     = subtotal,//Convert.ToInt32(gridView.Rows[rowindex].Cells[3].Value),
                Discount     = discount,
                Total        = total,
                TotalItems   = items, //Convert.ToString(gridView.Rows[rowindex].Cells[1].Value),
                CustomerName = customer,
                Status       = status
            });
            db.SubmitChanges();



            rowindex = 0;
        }
예제 #8
0
 public List <Product> GetAllProducts()
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         return(db.Products.Select(product => product).ToList());
     }
 }
예제 #9
0
 public List <T> FindAll(Func <T, bool> exp)
 {
     using (var db = new ShopDataContext())
     {
         return(db.GetTable <T>().Where(exp).ToList());
     }
 }
예제 #10
0
 public List <Sale> GetSalesByCustomerId(int id)
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         return(db.Sales.Where(sale => sale.customer.Equals(id)).ToList());
     }
 }
예제 #11
0
 public List <Sale> GetAllSales()
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         return(db.Sales.Select(sale => sale).ToList());
     }
 }
예제 #12
0
 public Sale GetLastSale()
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         return(db.Sales.Select(sale => sale).ToList().LastOrDefault());
     }
 }
예제 #13
0
 public T GetFirstOrDefault(Func <T, bool> exp)
 {
     using (var db = new ShopDataContext())
     {
         return(db.GetTable <T>().FirstOrDefault(exp));
     }
 }
예제 #14
0
파일: Orders.cs 프로젝트: adizka/iShop
        public void AddToCart(List<ProductCounter> prodIDs, Guid userID)
        {
            using (var db = new ShopDataContext())
            {
                var user = db.Users.First(u => u.UserID == userID);

                var order = user.Orders.FirstOrDefault(o => o.IsActive);

                if (order == null)
                {
                    order = new Order()
                    {
                        DeliveryTypeID = (int)DeliveryTypes.NotDelivered,
                        IsActive = true,
                        IsPaid = false,
                        OrderID = Guid.NewGuid(),
                        OrderStatusID = (int)OrderStatus.NotPaid,
                        PaymentTypeID = (int)PaymentTypes.PayPal,
                        UserID = userID,
                        CreateDate = DateTime.Now,
                        DeliveryDate = DateTime.Now,
                        CountryID = db.Countries.First().ID
                    };
                    db.Orders.InsertOnSubmit(order);
                }

                foreach (var item in prodIDs)
                {
                    var ord = order.OrdersRefProducts.FirstOrDefault(r => r.ProductID == item.ID);
                    int oldCount = 0;
                    BL.Product prod = null;
                    if (ord != null)
                    {
                        oldCount = ord.Count;
                        //ord.Count = Math.Min(item.Count, ord.Product.Count);
                        ord.CreateDate = DateTime.Now;
                    }
                    else
                    {
                        prod = db.Products.First(p => p.ProductID == item.ID);
                        if (prod == null)
                            continue;
                        ord = new OrdersRefProduct()
                        {
                            ProductID = item.ID,
                            ID = Guid.NewGuid(),
                            CreateDate = DateTime.Now,
                        };
                        oldCount = 0;
                        order.OrdersRefProducts.Add(ord);
                    }
                    prod = (prod == null) ? db.Products.First(p => p.ProductID == item.ID) : prod;
                    ord.Count += Math.Min(item.Count, prod.Count);
                    prod.Count -= ord.Count - oldCount;
                    prod.IsVisible = prod.Count > 0;

                }
                db.SubmitChanges();
            }
        }
예제 #15
0
 public Customer GetCustomerById(int id)
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         return(db.Customers.FirstOrDefault(customer => customer.id.Equals(id)));
     }
 }
예제 #16
0
 public List <Supply> GetAllSupplies()
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         return(db.Supplies.Select(supply => supply).ToList());
     }
 }
예제 #17
0
 public Product GetProductById(int id)
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         return(db.Products.FirstOrDefault(product => product.id.Equals(id)));
     }
 }
예제 #18
0
 public Supply GetLastSupply()
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         return(db.Supplies.Select(supply => supply).ToList().LastOrDefault());
     }
 }
예제 #19
0
 public Supply GetSupplyById(int id)
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         return(db.Supplies.FirstOrDefault(supply => supply.id.Equals(id)));
     }
 }
예제 #20
0
 public List <Supply> GetSuppliesByProductId(int id)
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         return(db.Supplies.Where(supply => supply.product.Equals(id)).ToList());
     }
 }
예제 #21
0
 public Customer GetLastCustomer()
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         return(db.Customers.Select(customer => customer).ToList().LastOrDefault());
     }
 }
예제 #22
0
 public List <T> All()
 {
     using (var db = new ShopDataContext())
     {
         return(db.GetTable <T>().ToList());
     }
 }
예제 #23
0
파일: Products.cs 프로젝트: adizka/iShop
        public bool AddProduct(string name, string unit, decimal price, bool isVisible, int count, decimal tax, decimal shipping, out BL.Product product)
        {
            bool addProduct = false;
            using (ShopDataContext db = new ShopDataContext())
            {
                product = new BL.Product();

                if (db.Products.Any(p => p.Name == name))
                    return false;
                BL.Modules.Products.ProductProperies ppbl = new ProductProperies();

                product.ProductID = Guid.NewGuid();
                product.Name = name;
                product.CreateDate = DateTime.Now;
                product.Unit = unit;
                product.Price = price;
                product.InStock = (count > 0);
                product.IsVisible = isVisible;
                product.ProductTypeID = (int)ProductType.Types.Real;
                product.Count = count;
                product.Tax = tax;
                product.Shipping = shipping;
                db.Products.InsertOnSubmit(product);
                db.SubmitChanges();
                addProduct = ppbl.AddProductPhoto(BL.Site.DefaultPhotoPreview, BL.Site.DefaultPhotoOriginal, product.ProductID);
                addProduct = true;

            }
            return addProduct;
        }
예제 #24
0
 public List <Customer> GetAllCustomers()
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         return(db.Customers.Select(customer => customer).ToList());
     }
 }
예제 #25
0
        private void PrepareData()
        {
            using (var model = new ShopDataContext())
            {
                var category = new Category {
                    Name = "tools"
                };
                var otherCategory = new Category {
                    Name = "food"
                };

                category.Products.Add(new Product()
                {
                    Name = "Notepad", Category = category, Price = 10.0
                });
                category.Products.Add(new Product()
                {
                    Name = "Pencil", Category = category, Price = 4.0
                });
                category.Products.Add(new Product()
                {
                    Name = "Pen", Category = category, Price = 6.0
                });
                otherCategory.Products.Add(new Product()
                {
                    Name = "Pear", Category = otherCategory, Price = 2.0
                });

                model.Categories.Add(category);
                model.Categories.Add(otherCategory);

                model.SaveChanges();
            }
        }
예제 #26
0
 public Sale GetSaleById(int id)
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         return(db.Sales.FirstOrDefault(sale => sale.id.Equals(id)));
     }
 }
 public ReturnEvent GetReturnEventById(int id)
 {
     using (var db = new ShopDataContext())
     {
         return(db.ReturnEvents.FirstOrDefault(ev => ev.Id.Equals(id)));
     }
 }
예제 #28
0
 public void AddProduct(Product product)
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         db.Products.InsertOnSubmit(product);
         db.SubmitChanges();
     }
 }
예제 #29
0
 public void AddSale(Sale sale)
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         db.Sales.InsertOnSubmit(sale);
         db.SubmitChanges();
     }
 }
예제 #30
0
 public void AddSupply(Supply supply)
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         db.Supplies.InsertOnSubmit(supply);
         db.SubmitChanges();
     }
 }
예제 #31
0
 public void CreateAdmin(string email, string password)
 {
     using (var db = new ShopDataContext())
     {
         db.Admins.InsertOnSubmit(new Admin {Email = email, Password = password});
         db.SubmitChanges();
     }
 }
예제 #32
0
 public void DeleteItems(List <T> items)
 {
     using (var db = new ShopDataContext())
     {
         db.GetTable <T>().DeleteAllOnSubmit(items);
         db.SubmitChanges();
     }
 }
예제 #33
0
 public void AddCustomer(Customer customer)
 {
     using (var db = new ShopDataContext(ShopDataConnection))
     {
         db.Customers.InsertOnSubmit(customer);
         db.SubmitChanges();
     }
 }
예제 #34
0
 public void AddUnit(Unit unit)
 {
     using (var db = new ShopDataContext())
     {
         db.Units.InsertOnSubmit(unit);
         db.SubmitChanges();
     }
 }
예제 #35
0
 public void ConfirmOrder(int id)
 {
     using (var db = new ShopDataContext())
     {
         var unit = db.Orders.FirstOrDefault(u => u.Id == id);
         unit.State = (int) OrderState.InProgress;
         db.SubmitChanges();
     }
 }
예제 #36
0
파일: Countries.cs 프로젝트: adizka/iShop
 public void AddCountry(string Name)
 {
     using (ShopDataContext db = new ShopDataContext())
     {
         db.Countries.InsertOnSubmit(new Country()
         {
             Name = Name
         });
         db.SubmitChanges();
     }
 }
예제 #37
0
파일: Countries.cs 프로젝트: adizka/iShop
 public bool DeleteCountry(int ID)
 {
     using (ShopDataContext db = new ShopDataContext())
     {
         var country = db.Countries.FirstOrDefault(c => c.ID == ID);
         if (country == null)
             return false;
         db.Countries.DeleteOnSubmit(country);
         db.SubmitChanges();
     }
     return true;
 }
		public void AllColumnsShouldBeMapped()
		{
			string connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=SutekiShop;Integrated Security=True";

			using (var context = new ShopDataContext(connectionString))
			{
				context.Log = Console.Out;

				foreach (var mappedTable in context.Mapping.GetTables().Select(x => x.RowType.Type)) 
				{
					context.GetTable(mappedTable).Cast<object>().Take(0).ToList();
				}
			}
		}
예제 #39
0
파일: Properties.cs 프로젝트: adizka/iShop
        public bool DeletePropertyById(Guid propertyId)
        {
            bool deletePropepry = false;

            using (ShopDataContext db = new ShopDataContext())
            {
                BL.CategoryProperty cp = db.CategoryProperties.Where(c => c.CategoriesPropertyID == propertyId).FirstOrDefault();
                if (cp != null)
                {
                    db.CategoryProperties.DeleteOnSubmit(cp);
                    db.SubmitChanges();
                    return true;
                }
            }
            return deletePropepry;
        }
예제 #40
0
 public void CreateOrder(IEnumerable<UnitOrderRelation> unitOrderRelations, CustomerInfo customerInfo)
 {
     var order = new Order();
     foreach (var rel in unitOrderRelations)
     {
         order.UnitOrderRelations.Add(rel);
     }
     customerInfo.FillOrder(order);
     order.TimeStamp = DateTime.Now;
     order.State = (int)OrderState.New;
     using (var hren = new ShopDataContext())
     {
         hren.Orders.InsertOnSubmit(order);
         hren.SubmitChanges();
     }
 }
예제 #41
0
파일: News.cs 프로젝트: adizka/iShop
 public void DeleteNewsById(int newsId)
 {
     using (var db = new ShopDataContext())
     {
         BL.News news = db.News.Where(n => n.NewsID == newsId).FirstOrDefault();
         if (news != null)
         {
             using (var ts = new TransactionScope())
             {
                 db.News.DeleteOnSubmit(news);
                 db.SubmitChanges();
                 ts.Complete();
             }
         }
     }
 }
예제 #42
0
파일: News.cs 프로젝트: adizka/iShop
 public void DeAcivateNewsById(int newsid)
 {
     using (var db = new ShopDataContext())
     {
         BL.News news = db.News.Where(n => n.NewsID == newsid).FirstOrDefault();
         if (news != null)
         {
             using (var ts = new TransactionScope())
             {
                 news.IsActive = false;
                 db.SubmitChanges();
                 ts.Complete();
             }
         }
     }
 }
예제 #43
0
 public bool AddProductRefCategoryes(Guid productId, Guid categoryId)
 {
     bool add = false;
     using (ShopDataContext db = new ShopDataContext())
     {
         BL.ProductsRefCategory prc = new BL.ProductsRefCategory();
         prc.ID = Guid.NewGuid();
         prc.ProductID = productId;
         prc.CategoryID = categoryId;
         prc.Sort = 0;
         db.ProductsRefCategories.InsertOnSubmit(prc);
         db.SubmitChanges();
         add = true;
     }
     return add;
 }
예제 #44
0
        public bool AddProductPhoto(string previewUrl, string originalUrl, Guid productId)
        {
            bool allRight = false;
            using (var db = new ShopDataContext())
            {
                BL.ProductProperty productPropertyPreview = new BL.ProductProperty();
                BL.ProductProperty productPropertyOriginal = new BL.ProductProperty();
                try
                {
                    using (var ts = new TransactionScope())
                    {
                        productPropertyPreview.PropertyID = Guid.NewGuid();
                        productPropertyOriginal.PropertyID = Guid.NewGuid();

                        productPropertyPreview.ProductID = productId;
                        productPropertyOriginal.ProductID = productId;

                        productPropertyPreview.PropertyName = ProductPhoto.ProductPhotoPreview.ToString();
                        productPropertyOriginal.PropertyName = ProductPhoto.ProductPhotoOriginal.ToString();

                        productPropertyPreview.PropertyValue = previewUrl;
                        productPropertyOriginal.PropertyValue = originalUrl;

                        productPropertyPreview.IsImportant = true;
                        productPropertyOriginal.IsImportant = true;

                        productPropertyPreview.Sort = 0;
                        productPropertyOriginal.Sort = 0;

                        db.ProductProperties.InsertOnSubmit(productPropertyPreview);
                        db.SubmitChanges();

                        db.ProductProperties.InsertOnSubmit(productPropertyOriginal);
                        db.SubmitChanges();

                        ts.Complete();
                        allRight = true;
                    }
                }
                catch (Exception)
                {
                    allRight = false;
                }
                return allRight;
            }
        }
예제 #45
0
 public bool AddProdProp(string name, string value, Guid productId)
 {
     bool allRight = false;
     using (var db = new ShopDataContext())
     {
         BL.ProductProperty productProp = new BL.ProductProperty();
         productProp.ProductID = productId;
         productProp.PropertyID = Guid.NewGuid();
         productProp.IsImportant = true;
         productProp.PropertyName = name;
         productProp.PropertyValue = value;
         productProp.Sort = 0;
         db.ProductProperties.InsertOnSubmit(productProp);
         db.SubmitChanges();
         allRight = true;
     }
     return allRight;
 }
예제 #46
0
파일: Categories.cs 프로젝트: adizka/iShop
 public void AddCategory(string name, Guid? parentId)
 {
     using (var db = new ShopDataContext())
     {
         BL.Category category = new BL.Category();
         using (var ts = new TransactionScope())
         {
             category.Name = name;
             category.CreateDate = DateTime.Now;
             category.ParentID = parentId;
             category.CategoryID = Guid.NewGuid();
             category.Sort = db.Categories.Count(c => c.ParentID == parentId);
             db.Categories.InsertOnSubmit(category);
             db.SubmitChanges();
             ts.Complete();
         }
     }
 }
예제 #47
0
 public void UpdateProductsRefCategoriesSort(List<Guid> prodIds)
 {
     using (var db = new ShopDataContext())
     {
         using (var ts = new TransactionScope())
         {
             var index = 0;
             foreach (var item in prodIds)
             {
                 var categ = db.ProductsRefCategories.First(c => c.ID == item);
                 categ.Sort = index;
                 index++;
             }
             db.SubmitChanges();
             ts.Complete();
         }
     }
 }
예제 #48
0
        public bool AddCategoriesToProduct(List<Guid> categoriesIds, Guid productId)
        {
            bool add = true;

            BL.Modules.Products.Products pbl = new BL.Modules.Products.Products();

            ShopDataContext db = new ShopDataContext();

            foreach (Guid item in categoriesIds)
            {
                BL.ProductsRefCategory prod = db.ProductsRefCategories.Where(c => c.CategoryID == item && c.ProductID == productId).FirstOrDefault();
                if (prod == null)
                {
                    add = pbl.AddCategoryToProduct(item, productId, db);
                }
            }
            return add;
        }
예제 #49
0
파일: Orders.cs 프로젝트: adizka/iShop
        public void ClearCart(Guid userID, Guid orderID)
        {
            using (var db = new ShopDataContext())
            {
                var user = db.Users.First(u => u.UserID == userID);
                var order = user.Orders.FirstOrDefault(o => o.OrderID == orderID && o.IsActive);

                if (order == null)
                    return;

                foreach (var item in order.OrdersRefProducts)
                {
                    item.Product.Count += item.Count;
                    item.Product.IsVisible = item.Product.Count > 0;
                }
                db.OrdersRefProducts.DeleteAllOnSubmit(order.OrdersRefProducts);
                db.SubmitChanges();
            }
        }
예제 #50
0
파일: Properties.cs 프로젝트: adizka/iShop
 public bool AddProperties(Guid categoryId, string name, string value, int sort)
 {
     bool saveProperty = false;
     using (ShopDataContext db = new ShopDataContext())
     {
         BL.Category category = db.Categories.Where(c => c.CategoryID == categoryId).FirstOrDefault();
         if (categoryId != null)
         {
             BL.CategoryProperty cp = new BL.CategoryProperty();
             cp.CategoriesID = categoryId;
             cp.PropertName = name;
             cp.PropertyValue = value;
             cp.Sort = (sort == -1) ? 0 : sort;
             cp.CategoriesPropertyID = Guid.NewGuid();
             db.CategoryProperties.InsertOnSubmit(cp);
             db.SubmitChanges();
             saveProperty = true;
         }
     }
     return saveProperty;
 }
예제 #51
0
파일: Properties.cs 프로젝트: adizka/iShop
        public bool UpdateAllPropertiesByCategoryId(IQueryable<BL.CategoryProperty> properties, Guid categoryId)
        {
            bool updateProperties = false;

            using (ShopDataContext db = new ShopDataContext())
            {
                BL.Category category = db.Categories.Where(c => c.CategoryID == categoryId).FirstOrDefault();
                if (category != null)
                {
                    using (var ts = new TransactionScope())
                    {
                        db.CategoryProperties.AttachAll(properties);
                        db.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, properties);
                        db.SubmitChanges();
                        ts.Complete();
                        updateProperties = true;
                    }
                }
            }
            return updateProperties;
        }
예제 #52
0
파일: Categories.cs 프로젝트: adizka/iShop
        public int DeleteCategoryByIdWithErrorMessage(Guid id)
        {
            if (CategoryHasChild(id))
            {
                return (int)DeleteErrors.HasChilds;
            }
            if (CategoryHasProducts(id))
            {
                return (int)DeleteErrors.HasProducts;
            }

            ShopDataContext db = new ShopDataContext();
            BL.Category category = db.Categories.Where(c => c.CategoryID == id).FirstOrDefault();
            if (category == null)
            {
                return (int)DeleteErrors.Invalid;
            }

            db.Categories.DeleteOnSubmit(category);
            db.SubmitChanges();
            return (int)DeleteErrors.Success;
        }
예제 #53
0
파일: Products.cs 프로젝트: adizka/iShop
        public void CopyProperties(Guid fromID, Guid toID)
        {
            using (ShopDataContext db = new ShopDataContext())
            {
                var fromProd = db.Products.First(p => p.ProductID == fromID);
                var toProd = db.Products.First(p => p.ProductID == toID);

                List<BL.ProductProperty> newProps = new List<BL.ProductProperty>();
                List<BL.ProductsRefProperty> newRefs = new List<ProductsRefProperty>();

                foreach (var item in fromProd.ProductProperties.Where(p =>
                        p.PropertyName != ProductPropertyConstants.ProductPhotoPreview
                        && p.PropertyName != ProductPropertyConstants.ProductPhotoOriginal
                        && p.PropertyName != ProductPropertyConstants.ProductDescription
                        && p.PropertyName != ProductPropertyConstants.ProductPhotoOriginal2
                        && p.PropertyName != ProductPropertyConstants.ProductPhotoOriginal3).OrderBy(pp => pp.Sort))
                {
                    var newProp = new ProductProperty()
                    {
                        IsImportant = item.IsImportant,
                        PropertyID = Guid.NewGuid(),
                        PropertyName = item.PropertyName,
                        PropertyValue = item.PropertyValue,
                        Sort = newProps.Count
                    };
                    newProps.Add(newProp);
                    newRefs.Add(new ProductsRefProperty()
                    {
                        ID = Guid.NewGuid(),
                        ProductPropertiesID = newProp.PropertyID,
                        Sort = newRefs.Count
                    });
                }
                toProd.ProductProperties.AddRange(newProps);
                toProd.ProductsRefProperies.AddRange(newRefs);

                db.SubmitChanges();
            }
        }
예제 #54
0
파일: Products.cs 프로젝트: adizka/iShop
        public bool AddCategoryToProduct(Guid categoryId, Guid productId, ShopDataContext db)
        {
            bool addCategoryToProduct = false;

            BL.Category category = db.Categories.FirstOrDefault(c => c.CategoryID == categoryId);
            if (category != null)
            {
                BL.Product product = db.Products.FirstOrDefault(p => p.ProductID == productId);
                if (product != null)
                {
                    if (product.ProductsRefCategories.Any(c => c.CategoryID == category.CategoryID))
                        return false;
                    BL.ProductsRefCategory prc = new ProductsRefCategory();
                    prc.ID = Guid.NewGuid();
                    prc.CategoryID = categoryId;
                    prc.ProductID = productId;
                    prc.Sort = category.ProductsRefCategories.Count();
                    product.ProductsRefCategories.Add(prc);
                    db.SubmitChanges();
                    addCategoryToProduct = true;
                }
            }
            return addCategoryToProduct;
        }
예제 #55
0
파일: Products.cs 프로젝트: adizka/iShop
        public bool UpdateProduct(Guid productId, string name, string unit, decimal price, bool isVisible, int count, decimal tax, decimal shipping)
        {
            bool updateProduct = false;

            using (ShopDataContext db = new ShopDataContext())
            {
                BL.Product product = db.Products.FirstOrDefault(p => p.ProductID == productId);
                if (product.Name != name && db.Products.Count(p => p.Name == name) == 1)
                    return false;
                if (product != null)
                {
                    using (var ts = new TransactionScope())
                    {
                        product.Name = name;
                        product.Unit = unit;
                        product.Price = price;
                        product.IsVisible = isVisible;
                        product.InStock = (count > 0);
                        product.Count = count;
                        product.Tax = tax;
                        product.Shipping = shipping;
                        updateProduct = true;
                        db.SubmitChanges();
                        ts.Complete();
                    }
                }
            }
            return updateProduct;
        }
예제 #56
0
파일: Products.cs 프로젝트: adizka/iShop
 public BL.Product GetProductById(Guid productId)
 {
     ShopDataContext db = new ShopDataContext();
     return db.Products.FirstOrDefault(p => p.ProductID == productId);
 }
예제 #57
0
파일: Products.cs 프로젝트: adizka/iShop
 public IQueryable<BL.Product> GetProductByCategories(Guid categoryId)
 {
     ShopDataContext db = new ShopDataContext();
     List<Guid> ids = new List<Guid>();
     IQueryable<BL.ProductsRefCategory> rpcs = db.ProductsRefCategories.Where(r => r.CategoryID == categoryId);
     if (rpcs.Any())
     {
         foreach (var item in rpcs)
         {
             ids.Add(item.ProductID);
         }
         List<BL.Product> products = new List<Product>();
         foreach (var item in ids)
         {
             try
             {
                 products.Add(db.Products.Where(p => p.ProductID == item).FirstOrDefault());
             }
             catch
             {
                 return null;
             }
         }
         return products.AsQueryable();
     }
     return null;
 }
예제 #58
0
파일: Products.cs 프로젝트: adizka/iShop
 public IQueryable<BL.Product> GetMostPopularProducts()
 {
     var db = new ShopDataContext();
     //IList<BL.Product> products = db.Products.ToList();
     //if (products.Count < 10)
     //{
         return db.Products.Take(10);
     //}
     //List<BL.Product> prods = new List<Product>();
     //for (int i = 0; i < 10; i++)
     //{
     //    Random _r = new Random();
     //    int n = _r.Next(products.Count());
     //    prods.Add(products[n]);
     //}
     //return null;
 }
예제 #59
0
파일: Products.cs 프로젝트: adizka/iShop
        public void DeleteProductCategories(Guid productID)
        {
            BL.Product poducts = new BL.Product();

            BL.ShopDataContext ctx = new ShopDataContext();
            var refs = ctx.ProductsRefCategories.Where(r => r.ProductID == productID);

            foreach (var item in refs)
            {
                var catRef = item.Category.ProductsRefCategories.Where(s => s.Sort > item.Sort);
                foreach (var refs1 in catRef)
                {
                    refs1.Sort--;
                }
            }

            ctx.ProductsRefCategories.DeleteAllOnSubmit(refs);
            ctx.SubmitChanges();
        }
예제 #60
0
파일: Products.cs 프로젝트: adizka/iShop
        public void DeleteProduct(Guid prodID)
        {
            using (ShopDataContext db = new ShopDataContext())
            {
                var prod = db.Products.FirstOrDefault(p => p.ProductID == prodID);
                if (prod == null) return;

                db.ProductsRefCategories.DeleteAllOnSubmit(prod.ProductsRefCategories);
                db.OrdersRefProducts.DeleteAllOnSubmit(prod.OrdersRefProducts);
                db.ProductsRefProperies.DeleteAllOnSubmit(prod.ProductsRefProperies);
                db.ProductProperties.DeleteAllOnSubmit(prod.ProductProperties);
                db.Stocks.DeleteAllOnSubmit(prod.Stocks);
                db.Products.DeleteOnSubmit(prod);
                db.SubmitChanges();
            }
        }