Ejemplo n.º 1
0
        public ActionResult getLineItem(string variantChoiced, string query)
        {
            try
            {
                LineItemsOfOrder productVariantOfProduct = new LineItemsOfOrder();
                List <Product>   products = new List <Product>();
                if (string.IsNullOrEmpty(query))
                {
                    products = productService.GetAll();
                }
                else
                {
                    string where = string.Format("ProductName like N'%{0}%' or Tags like N'%{1}%' ", query, query);
                    where       += string.Format(" or ProductID in (select Product.ProductID from Product left join TblOption on Product.ProductID = TblOption.ProductID " +
                                                 " where OptionValue like N'%{0}%')", query);
                    products = productService.GetByWhere(where);
                }

                List <int> variantIDs = new List <int>();
                if (!string.IsNullOrEmpty(variantChoiced))
                {
                    variantChoiced = SString.RemoveElementAtBeginEnd(variantChoiced, ",");
                    string[] temp = variantChoiced.Split(',');
                    foreach (var item in temp)
                    {
                        variantIDs.Add(SNumber.ToNumber(item));
                    }
                }

                if (products != null && products.Count > 0)
                {
                    foreach (var item in products)
                    {
                        List <Variant> variants = variantService.GetByProductID(item.ProductID);
                        if (variants != null && variants.Count > 0)
                        {
                            if (variants.Count == 1 && variants[0].Option1 == "Default Title")
                            {
                                LineItem temp = new LineItem();
                                temp.VariantID  = variants[0].VariantID;
                                temp.SKU        = variants[0].VariantSKU;
                                temp.ProductID  = item.ProductID;
                                temp.ObjectName = item.ProductName;
                                temp.IsDefault  = true;
                                temp.Price      = SNumber.ToNumber(variants[0].VariantPrice);
                                temp.Quantity   = 1;

                                var thumb = ImageService.GetPathImageFirstOfProduct(item.ProductID);
                                temp.ImageUrl = thumb;
                                if (!variantIDs.Contains(temp.VariantID))
                                {
                                    temp.CanChoice = true;
                                }
                                else
                                {
                                    temp.CanChoice = false;
                                }
                                productVariantOfProduct.ProductVariants.Add(temp);
                            }
                            else
                            {
                                LineItem product = new LineItem();
                                product.VariantID  = 0;
                                product.ProductID  = item.ProductID;
                                product.ObjectName = item.ProductName;
                                product.IsDefault  = true;
                                product.Price      = -1;
                                product.CanChoice  = false;
                                product.Quantity   = 1;
                                var thumb = ImageService.GetPathImageFirstOfProduct(item.ProductID);
                                product.ImageUrl = thumb;
                                productVariantOfProduct.ProductVariants.Add(product);

                                for (int i = 0; i < variants.Count; i++)
                                {
                                    LineItem temp = new LineItem();
                                    temp.ProductID  = item.ProductID;
                                    temp.VariantID  = variants[i].VariantID;
                                    temp.ObjectName = variants[i].VariantTittle;
                                    temp.SKU        = variants[i].VariantSKU;
                                    temp.IsDefault  = false;
                                    temp.Price      = SNumber.ToNumber(variants[i].VariantPrice);
                                    temp.Quantity   = 1;
                                    if (!variantIDs.Contains(temp.VariantID))
                                    {
                                        temp.CanChoice = true;
                                    }
                                    else
                                    {
                                        temp.CanChoice = false;
                                    }

                                    TblImage image = imageService.GetByPrimaryKey(variants[i].ImageID);
                                    if (image != null)
                                    {
                                        temp.ImageUrl = image.ImageUrl;
                                    }
                                    productVariantOfProduct.ProductVariants.Add(temp);
                                }
                            }
                        }
                    }
                }
                return(View(productVariantOfProduct));
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                return(null);
            }
        }
Ejemplo n.º 2
0
        public ActionResult index(ProductModel productModel, int page = 1)
        {
            string strWhere = "";
            List <ProductStyle> productStyle = productStyleService.GetAll();

            productStyle.Insert(0, new ProductStyle {
                ProductStyleID = 0, ProductStyleName = "Tất cả"
            });
            ViewBag.ddlProductStyle = new SelectList(productStyle, "ProductStyleID", "ProductStyleName");

            List <Supplier> supplier = supplierService.GetAll();

            supplier.Insert(0, new Supplier {
                SupplierID = 0, SupplierName = "Tất cả"
            });
            ViewBag.ddlSupplier = new SelectList(supplier, "SupplierID", "SupplierName");

            int pageSize = int.MaxValue;

            strWhere = "";
            string strCondition = "";

            if (!string.IsNullOrEmpty(productModel.txtConditionFind))
            {
                strCondition += string.Format(" and (ProductName like N'%{0}%' or ProductContent like N'%{1}%' or ProductTitleCard like N'%{2}%' or ProductDescriptionCard like N'%{3}%' or ProductAlias like N'%{4}%' or Tags like N'%{5}%')",
                                              productModel.txtConditionFind, productModel.txtConditionFind, productModel.txtConditionFind, productModel.txtConditionFind, productModel.txtConditionFind, productModel.txtConditionFind);
            }

            if (productModel.ddlConditionFilter == "ddlDisplayStatus")
            {
                if (!string.IsNullOrEmpty(productModel.ddlDisplayStatus))
                {
                    strWhere = "ProductState = " + productModel.ddlDisplayStatus + strCondition;
                }
            }
            else if (productModel.ddlConditionFilter == "ddlProductStyle")
            {
                if (SNumber.ToNumber(productModel.ddlProductStyle) > 0)
                {
                    strWhere = "ProductStyleID = " + productModel.ddlProductStyle + strCondition;
                }
            }
            else if (productModel.ddlConditionFilter == "ddlSupplier")
            {
                if (SNumber.ToNumber(productModel.ddlSupplier) > 0)
                {
                    strWhere = "SupplierID = " + productModel.ddlSupplier + strCondition;
                }
            }
            if (string.IsNullOrEmpty(strWhere))
            {
                if (!string.IsNullOrEmpty(strCondition) && strCondition.Length > 4)
                {
                    strWhere = strCondition.Substring(4);
                }
                else
                {
                    strWhere = "";
                }
            }

            List <Product> lst = productService.GetByWhere(strWhere);

            productModel.lstProduct = lst.ToPagedList(page, pageSize);
            return(View(productModel));
        }
Ejemplo n.º 3
0
        public ActionResult detail(Product product)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (CheckInput(product))
                    {
                        if (product.SupplierID == 0)
                        {
                            product.SupplierID = null;
                        }
                        if (product.ProductStyleID == 0)
                        {
                            product.ProductStyleID = null;
                        }
                        product.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow();
                        if (!string.IsNullOrEmpty(product.Tags))
                        {
                            string[] tags = product.Tags.Split(',');
                            foreach (var item in tags)
                            {
                                if (!tagService.CheckExistTag(item, (int)Common.TableName.Product))
                                {
                                    Tag tag = new Tag();
                                    tag.TagName     = item;
                                    tag.TableNameID = (int)Common.TableName.Product;

                                    int tagID = tagService.Insert(tag);
                                }
                            }
                        }
                        bool flg = productService.Update(product);
                        if (flg)
                        {
                            LogService.WriteLog2DB(accountService.GetUserId(User.Identity.GetUserName()), (int)Common.ActionID.Update, product.ProductID, SDateTime.GetYYYYMMddHmmSSNow(), General.GetIPAddress(), TableNameID, product.ProductName);
                        }

                        // update variant defaul || update list variant
                        if (!product.AutoGenerate)
                        {
                            // variant default
                            if (product.Variant.VariantID > 0)
                            {
                                Variant variant = variantService.GetByPrimaryKey(product.Variant.VariantID);
                                variant.VariantPrice     = product.Variant.VariantPrice;
                                variant.CompareWithPrice = product.Variant.CompareWithPrice;
                                variant.Textable         = product.Variant.Textable;
                                variant.VariantSKU       = product.Variant.VariantSKU;
                                variant.VariantBarcode   = product.Variant.VariantBarcode;
                                variant.VariantWeight    = product.Variant.VariantWeight;
                                variant.WeightUnit       = product.Variant.WeightUnit;
                                variant.RequireShipping  = product.Variant.RequireShipping;
                                variant.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow();
                                bool updateVariant = variantService.Update(variant);
                            }
                            // has list variant
                            else
                            {
                                if (product.Variants != null && product.Variants.Count > 0)
                                {
                                    for (int i = 0; i < product.Variants.Count; i++)
                                    {
                                        product.Variants[i].VariantTittle    = variantService.GetVariantTittle(product.Variants[i]);
                                        product.Variants[i].ProductID        = product.ProductID;
                                        product.Variants[i].ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow();
                                        bool updateVariantFlg = variantService.Update(product.Variants[i]);
                                    }
                                }
                            }
                        }
                        // add variant, add option
                        else
                        {
                            if (product.Variants != null && product.Variants.Count > 0)
                            {
                                variantService.DeleteByProductID(product.ProductID);
                                for (int i = 0; i < product.Variants.Count; i++)
                                {
                                    Variant variant = product.Variants[i];
                                    if (variant.IsCreate)
                                    {
                                        if (SNumber.ToNumber(variant.VariantPrice) <= 0)
                                        {
                                            variant.VariantPrice = SNumber.ToNumber(product.Variant.VariantPrice) >= 0 ? product.Variant.VariantPrice : 0;
                                        }
                                        if (string.IsNullOrEmpty(variant.VariantSKU))
                                        {
                                            variant.VariantSKU = product.Variant.VariantSKU + "_" + (i + 1);
                                        }
                                        if (string.IsNullOrEmpty(variant.VariantBarcode))
                                        {
                                            variant.VariantSKU = product.Variant.VariantBarcode;
                                        }
                                        variant.CompareWithPrice = product.Variant.CompareWithPrice;
                                        variant.Textable         = product.Variant.Textable;
                                        variant.VariantWeight    = product.Variant.VariantWeight;
                                        variant.WeightUnit       = product.Variant.WeightUnit;
                                        variant.RequireShipping  = product.Variant.RequireShipping;
                                        variant.VariantBarcode   = product.Variant.VariantBarcode;
                                        variant.ProductID        = product.ProductID;
                                        variant.VariantTittle    = variantService.GetVariantTittle(variant);
                                        variant.CreatedDateTime  = variant.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow();
                                        int variantID = variantService.Insert(variant);
                                    }
                                }
                            }

                            //option
                            if (product.Options != null && product.Options.Count > 0)
                            {
                                for (int i = 0; i < product.Options.Count; i++)
                                {
                                    if (i == 0)
                                    {
                                        TblOption optionDefault = optionService.GetOptionDefaultOfProduct(product.ProductID);

                                        if (optionDefault != null)
                                        {
                                            optionDefault.OptionName       = product.Options[i].OptionName;
                                            optionDefault.OptionValue      = product.Options[i].OptionValue;
                                            optionDefault.ProductID        = product.ProductID;
                                            optionDefault.Position         = 1;
                                            optionDefault.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow();
                                            bool updateOptionDefault = optionService.Update(optionDefault);
                                        }
                                    }
                                    else
                                    {
                                        TblOption option = product.Options[i];
                                        option.ProductID        = product.ProductID;
                                        option.Position         = i + 1;
                                        option.CreatedDateTime  = SDateTime.GetYYYYMMddHmmSSNow();
                                        option.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow();
                                        int optionID = optionService.Insert(option);
                                    }
                                }
                            }
                        }
                        optionService.UpdateOptionOfProduct(product.ProductID);
                        return(RedirectToAction("detail", "products", new { id = product.ProductID, strMessage = "1" }));
                    }
                }
                catch (Exception ex)
                {
                    LogService.WriteException(ex);
                    return(RedirectToAction("", "products"));
                }
            }
            product.ListTag  = tagService.GetByTableNameID((int)Common.TableName.Product);
            product.Options  = optionService.GetByProductID(product.ProductID);
            product.Variants = variantService.GetByProductID(product.ProductID);
            product.Variant  = null;
            if (product.Variants != null && product.Variants.Count > 0)
            {
                if (!string.IsNullOrEmpty(product.Variants[0].Option1) && product.Variants[0].Option1.Equals("Default Title"))
                {
                    product.Variant  = product.Variants[0];
                    product.Variants = null;
                }
            }
            product.AutoGenerate = false;
            List <TblImage> images = imageService.GetByProductID(product.ProductID);

            product.Images = images;

            List <ProductStyle> productStyle = productStyleService.GetAll();

            productStyle.Insert(0, new ProductStyle {
                ProductStyleID = 0, ProductStyleName = "Chọn loại sản phẩm"
            });
            product.ProductStyles = new SelectList(productStyle, "ProductStyleID", "ProductStyleName", product.ProductStyleID.ToString());

            List <Supplier> supplier = supplierService.GetAll();

            supplier.Insert(0, new Supplier {
                SupplierID = 0, SupplierName = "Chọn nhà sản xuất"
            });
            product.Suppliers = new SelectList(supplier, "SupplierID", "SupplierName", product.SupplierID);
            foreach (ModelState modelState in ViewData.ModelState.Values)
            {
                foreach (ModelError error in modelState.Errors)
                {
                    strErrorMessage += error.ErrorMessage;
                }
            }
            ViewBag.strError = strErrorMessage;
            return(View(product));
        }
Ejemplo n.º 4
0
        public string create(Product product)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!CheckInput(product))
                    {
                        return(strErrorMessage);
                    }
                    if (product.SupplierID == 0)
                    {
                        product.SupplierID = null;
                    }
                    if (product.ProductStyleID == 0)
                    {
                        product.ProductStyleID = null;
                    }
                    product.CreatedDateTime = product.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow();

                    if (!string.IsNullOrEmpty(product.Tags))
                    {
                        string[] tags = product.Tags.Split(',');
                        if (tags != null && tags.Length > 0)
                        {
                            foreach (var item in tags)
                            {
                                if (!tagService.CheckExistTag(item, (int)Common.TableName.Product))
                                {
                                    Tag tag = new Tag();
                                    tag.TagName     = item;
                                    tag.TableNameID = (int)Common.TableName.Product;
                                    int tagID = tagService.Insert(tag);
                                }
                            }
                        }
                    }

                    int productID = productService.Insert(product);
                    if (productID > 0)
                    {
                        LogService.WriteLog2DB(accountService.GetUserId(User.Identity.GetUserName()), (int)Common.ActionID.Insert, productID, SDateTime.GetYYYYMMddHmmSSNow(), General.GetIPAddress(), TableNameID, product.ProductName);

                        //image
                        for (int i = 0; i < product.UploadeImages.Count; i++)
                        {
                            UploadImage(productID, product.UploadeImages[i]);
                        }
                        bool createVariantDefault = true;

                        if (product.AutoGenerate)
                        {
                            //variant
                            if (product.Variants != null && product.Variants.Count > 0)
                            {
                                for (int i = 0; i < product.Variants.Count; i++)
                                {
                                    Variant variant = product.Variants[i];
                                    if (variant.IsCreate)
                                    {
                                        createVariantDefault = false;
                                        if (SNumber.ToNumber(variant.VariantPrice) <= 0)
                                        {
                                            variant.VariantPrice = SNumber.ToNumber(product.Variant.VariantPrice) >= 0 ? product.Variant.VariantPrice : 0;
                                        }
                                        if (string.IsNullOrEmpty(variant.VariantSKU))
                                        {
                                            variant.VariantSKU = product.Variant.VariantSKU + "_" + (i + 1);
                                        }
                                        if (string.IsNullOrEmpty(variant.VariantBarcode))
                                        {
                                            variant.VariantSKU = product.Variant.VariantBarcode;
                                        }
                                        variant.CompareWithPrice = product.Variant.CompareWithPrice;
                                        variant.Textable         = product.Variant.Textable;
                                        variant.VariantWeight    = product.Variant.VariantWeight;
                                        variant.WeightUnit       = product.Variant.WeightUnit;
                                        variant.RequireShipping  = product.Variant.RequireShipping;
                                        variant.ProductID        = productID;
                                        variant.CreatedDateTime  = variant.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow();
                                        variant.VariantTittle    = variantService.GetVariantTittle(variant);
                                        variantService.Insert(variant);
                                    }
                                }
                            }
                        }
                        if (createVariantDefault)
                        {
                            product.Variant.ProductID       = productID;
                            product.Variant.CreatedDateTime = SDateTime.GetYYYYMMddHmmSSNow();
                            product.Variant.Option1         = product.Variant.VariantTittle = "Default Title";
                            product.Variant.Option2         = null;
                            product.Variant.Option3         = null;
                            product.Variant.CreatedDateTime = product.Variant.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow();
                            variantService.Insert(product.Variant);

                            TblOption option = new TblOption();
                            option.OptionName      = "Title";
                            option.ProductID       = productID;
                            option.OptionValue     = "Default Title";
                            option.Position        = 1;
                            option.CreatedDateTime = option.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow();
                            optionService.Insert(option);
                        }
                        else
                        {
                            //option
                            if (product.Options != null && product.Options.Count > 0)
                            {
                                for (int i = 0; i < product.Options.Count; i++)
                                {
                                    TblOption option = product.Options[i];
                                    option.ProductID        = productID;
                                    option.Position         = (i + 1);
                                    option.CreatedDateTime  = SDateTime.GetYYYYMMddHmmSSNow();
                                    option.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow();
                                    optionService.Insert(option);
                                }
                            }
                        }
                        return(productID.ToString());
                    }
                }

                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        strErrorMessage += error.ErrorMessage;
                    }
                }
                return(strErrorMessage);
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                return("Thêm sản phẩm lỗi");
            }
            //return View(product);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// get number order of a customer
 /// </summary>
 /// <param name="customerID">id of customer</param>
 /// <returns>number order</returns>
 public static object GetTotalOrderOfCustomer(int customerID)
 {
     try
     {
         IDbConnection connect    = new SqlConnection(Common.ConnectString);
         string        query      = "select count(*) from TblOrder where CustomerID = " + SNumber.ToNumber(customerID);
         int           totalOrder = SNumber.ToNumber(connect.Query <int>(query).Single());
         return(totalOrder);
     }
     catch (Exception ex)
     {
         LogService.WriteException(ex);
         return(0);
     }
 }
Ejemplo n.º 6
0
 public Collection GetByPrimaryKey(int collectionID)
 {
     try
     {
         string     query      = "select * from Collection where CollectionID = " + SNumber.ToNumber(collectionID);
         Collection collection = connect.Query <Collection>(query).FirstOrDefault <Collection>();
         if (collection != null)
         {
             collection.TblRules = tblRuleService.SelectByCollectionID(collectionID);
         }
         return(collection);
     }
     catch (Exception ex)
     {
         LogService.WriteException(ex);
         return(null);
     }
 }
Ejemplo n.º 7
0
 public AddressBook GetByPrimaryKey(int addressBookID)
 {
     try
     {
         string      query       = "select * from AddressBook where AddressBookID = " + SNumber.ToNumber(addressBookID);
         AddressBook AddressBook = connect.Query <AddressBook>(query).FirstOrDefault <AddressBook>();
         return(AddressBook);
     }
     catch (Exception ex)
     {
         LogService.WriteException(ex);
         return(new AddressBook());
     }
 }
Ejemplo n.º 8
0
        private static object TranslateNumber(SNumber obj)
        {
            var value = obj.Value;

            return(Math.Abs(value % 1) < double.Epsilon ? (int)value : value);
        }
Ejemplo n.º 9
0
 public List <Variant> GetByProductID(int productID)
 {
     try
     {
         string         query    = "select * from Variant where ProductID = " + SNumber.ToNumber(productID);
         List <Variant> variants = connect.Query <Variant>(query).ToList <Variant>();
         return(variants);
     }
     catch (Exception ex)
     {
         LogService.WriteException(ex);
         return(null);
     }
 }
Ejemplo n.º 10
0
 public List <TblOption> GetByProductID(int productID)
 {
     try
     {
         string           query      = "select * from TblOption where ProductID = " + SNumber.ToNumber(productID);
         List <TblOption> TblOptions = connect.Query <TblOption>(query).ToList <TblOption>();
         return(TblOptions);
     }
     catch (Exception ex)
     {
         LogService.WriteException(ex);
         return(new List <TblOption>());
     }
 }
Ejemplo n.º 11
0
        public ActionResult index(CustomerModel customerModel, int page = 1)
        {
            try
            {
                int pageSize   = int.MaxValue;
                int totalOrder = SNumber.ToNumber(customerModel.txtTotalOrder);

                string strWhere = "1=1";

                if (customerModel.ddlConditionFilter == "TotalOrder")
                {
                    if (!string.IsNullOrEmpty(customerModel.ddlCompareTotalOrder))
                    {
                        string expression = "";
                        if (customerModel.ddlCompareTotalOrder.Equals("equals"))
                        {
                            expression = "=";
                        }
                        else if (customerModel.ddlCompareTotalOrder.Equals("notequals"))
                        {
                            expression = "<>";
                        }
                        else if (customerModel.ddlCompareTotalOrder.Equals("greater"))
                        {
                            expression = ">";
                        }
                        else if (customerModel.ddlCompareTotalOrder.Equals("smaller"))
                        {
                            expression = "<";
                        }
                        if (!string.IsNullOrEmpty(expression))
                        {
                            strWhere += " and TotalOrder " + expression + customerModel.txtTotalOrder;
                        }
                    }
                }
                else if (customerModel.ddlConditionFilter == "TotalCount")
                {
                    if (!string.IsNullOrEmpty(customerModel.ddlCompareTotalCount))
                    {
                        string expression = "";
                        if (customerModel.ddlCompareTotalCount.Equals("equals"))
                        {
                            expression = "=";
                        }
                        else if (customerModel.ddlCompareTotalCount.Equals("notequals"))
                        {
                            expression = "<>";
                        }
                        else if (customerModel.ddlCompareTotalCount.Equals("greater"))
                        {
                            expression = ">";
                        }
                        else if (customerModel.ddlCompareTotalCount.Equals("smaller"))
                        {
                            expression = "<";
                        }
                        if (!string.IsNullOrEmpty(expression))
                        {
                            strWhere += " and TotalCount " + expression + customerModel.txtTotalCount;
                        }
                    }
                }
                else if (customerModel.ddlConditionFilter == "AcceptsMarketing")
                {
                    string acceptsMarketing = "0";
                    if (customerModel.ddlAcceptsMarketing.Equals("true"))
                    {
                        acceptsMarketing = "1";
                    }
                    strWhere += " and AcceptsMarketing = " + acceptsMarketing;
                }
                else if (customerModel.ddlConditionFilter == "State")
                {
                    string state = "0";
                    if (customerModel.ddlState.Equals("enable"))
                    {
                        state = "1";
                    }
                    strWhere += " and CustomerState = " + state;
                }

                if (!string.IsNullOrEmpty(customerModel.txtConditionFind))
                {
                    strWhere += string.Format(" and (CustomerFirstName like N'%{0}%' or CustomerLastName like N'%{1}%' or CustomerEmail like N'%{2}%') order by ModifiedDate,CreatedDate", customerModel.txtConditionFind, customerModel.txtConditionFind, customerModel.txtConditionFind);
                }

                List <Customer> customers = customerService.SelectByWhere(strWhere).ToList <Customer>();
                if (customers != null && customers.Count > 0)
                {
                    customerModel.lstCustomer = customers.ToPagedList(page, pageSize);
                }
                return(View(customerModel));
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                return(View(customerModel));
            }
        }
Ejemplo n.º 12
0
        // GET: client/products
        public ActionResult index(ProductClientViewModel productClientViewModel)
        {
            try
            {
                string         orderby = "ProductName", sortOrder = "asc";
                List <Product> products = null;

                if (!string.IsNullOrEmpty(productClientViewModel.sortOrder))
                {
                    if (productClientViewModel.sortOrder.Equals("name-asc"))
                    {
                        orderby   = "ProductName";
                        sortOrder = "asc";
                    }
                    else if (productClientViewModel.sortOrder.Equals("name-desc"))
                    {
                        orderby   = "ProductName";
                        sortOrder = "desc";
                    }
                    else if (productClientViewModel.sortOrder.Equals("create-desc"))
                    {
                        orderby   = "CreatedDateTime";
                        sortOrder = "desc";
                    }
                    else if (productClientViewModel.sortOrder.Equals("best-selling"))
                    {
                        products = productService.GetBestSelling();
                    }
                }
                if (SNumber.ToNumber(productClientViewModel.numberView) == 0)
                {
                    productClientViewModel.numberView = 9;
                }

                // not find product
                if (products == null || products.Count == 0)
                {
                    products = productService.GetAll(orderby, sortOrder);
                }
                // get variant and images for product
                if (products != null && products.Count > 0)
                {
                    for (int i = 0; i < products.Count; i++)
                    {
                        products[i].Variants = variantService.GetByProductID(products[i].ProductID);
                        products[i].Images   = imageService.GetByProductID(products[i].ProductID);
                    }
                }
                if (SNumber.ToNumber(productClientViewModel.pageNumber) == 0)
                {
                    productClientViewModel.pageNumber = 1;
                }
                productClientViewModel.CountProduct = products.Count;
                productClientViewModel.Products     = products.ToPagedList(productClientViewModel.pageNumber, productClientViewModel.numberView);

                if (productClientViewModel.view == "list")
                {
                    return(View("list", productClientViewModel));
                }
                else
                {
                    return(View("grid", productClientViewModel));
                }
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                throw;
            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// get total cost of all order of a customer
 /// </summary>
 /// <param name="customerID">id of customer</param>
 /// <returns>total count</returns>
 public static object GetTotalCountOfCustomer(int customerID)
 {
     try
     {
         IDbConnection   connect     = new SqlConnection(Common.ConnectString);
         string          query       = "select * from TblOrder where CustomerID = " + SNumber.ToNumber(customerID);
         List <TblOrder> lstTblOrder = connect.Query <TblOrder>(query).ToList <TblOrder>();
         decimal         totalCount  = 0;
         for (int i = 0; i < lstTblOrder.Count; i++)
         {
             totalCount += lstTblOrder[i].TotalCount;
         }
         return(totalCount);
     }
     catch (Exception ex)
     {
         LogService.WriteException(ex);
         return(0);
     }
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Creates an instance of the number primitive.
 /// </summary>
 internal SNumber CreateNumber(double value)
 {
     return(SNumber.Factory(value));
 }
Ejemplo n.º 15
0
        public ActionResult create(CreateOrderModel createOrderModel)
        {
            if (ModelState.IsValid)
            {
                int billingAddressID = 0, shippingAddressID = 0;

                decimal totalCount = 0;
                if (createOrderModel.LineItems != null && createOrderModel.LineItems.Count > 0)
                {
                    foreach (var item in createOrderModel.LineItems)
                    {
                        totalCount += item.Price * item.Quantity;
                    }
                }

                TblOrder order = new TblOrder();
                order.OrderStatus = Common.Active;
                if (createOrderModel.Customer != null)
                {
                    order.CustomerEmail = createOrderModel.Customer.CustomerEmail;
                    if (SNumber.ToNumber(createOrderModel.Customer.CustomerID) > 0)
                    {
                        order.CustomerID = createOrderModel.Customer.CustomerID;

                        BillingAddress billingAddress = new BillingAddress();
                        billingAddress.CountryID    = createOrderModel.BillingAddress.CountryID;
                        billingAddress.CountryName  = createOrderModel.BillingAddress.CountryName;
                        billingAddress.CustomerName = createOrderModel.BillingAddress.CustomerName;
                        billingAddress.HomeAddress  = createOrderModel.BillingAddress.HomeAddress;
                        billingAddress.Phone        = createOrderModel.BillingAddress.Phone;
                        billingAddress.ProvinceName = createOrderModel.BillingAddress.ProvinceName;
                        billingAddressID            = billingAddressService.Insert(billingAddress);

                        ShippingAddress shippingAddress = new ShippingAddress();
                        shippingAddress.CountryID    = createOrderModel.ShippingAddress.CountryID;
                        shippingAddress.CountryName  = createOrderModel.ShippingAddress.CountryName;
                        shippingAddress.CustomerName = createOrderModel.ShippingAddress.CustomerName;
                        shippingAddress.HomeAddress  = createOrderModel.ShippingAddress.HomeAddress;
                        shippingAddress.Phone        = createOrderModel.ShippingAddress.Phone;
                        shippingAddress.ProvinceName = createOrderModel.ShippingAddress.ProvinceName;
                        shippingAddressID            = shippingAddressService.Insert(shippingAddress);
                    }
                    else
                    {
                        order.CustomerID = null;
                    }
                    order.BillingStatus  = createOrderModel.BillingStatus;
                    order.ShippingStatus = Common.Unfulfilled;
                    order.OrderNote      = createOrderModel.OrderNote;
                    order.OrderStatus    = Common.Active;
                    if (shippingAddressID == 0)
                    {
                        order.ShippingAddressID = null;
                    }
                    else
                    {
                        order.ShippingAddressID = shippingAddressID;
                    }
                    if (billingAddressID == 0)
                    {
                        order.BillingAddressID = null;
                    }
                    else
                    {
                        order.BillingAddressID = billingAddressID;
                    }
                    order.TotalCount      = totalCount;
                    order.Number          = orderService.GetLastNumber() + 1;
                    order.CreatedDateTime = order.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow();

                    int orderID = orderService.Insert(order);

                    if (SNumber.ToNumber(orderID) > 0)
                    {
                        if (order.BillingStatus == Common.Paid)
                        {
                            if (SNumber.ToNumber(order.CustomerID) > 0)
                            {
                                Customer customer = customerService.GetByPrimaryKey(SNumber.ToNumber(order.CustomerID));
                                customer.TotalCount      += totalCount;
                                customer.TotalOrder      += 1;
                                customer.ModifiedDateTime = SDateTime.GetYYYYMMddHmmSSNow();
                                customerService.Update(customer);
                            }
                        }

                        string orderName = "#" + (Common.BaseNumberOrder + order.Number).ToString();
                        LogService.WriteLog2DB(accountService.GetUserId(User.Identity.GetUserName()), (int)Common.ActionID.Insert, orderID, SDateTime.GetYYYYMMddHmmSSNow(), General.GetIPAddress(), TableNameID, orderName);
                        if (createOrderModel.LineItems != null && createOrderModel.LineItems.Count > 0)
                        {
                            foreach (var item in createOrderModel.LineItems)
                            {
                                item.OrderID        = orderID;
                                item.ShippingStatus = null;
                                if (item.IsDefault)
                                {
                                    item.VariantName = "Default Title";
                                }
                                lineItemService.Insert(item);
                            }
                        }
                        return(Json(new { id = orderID }));
                    }
                }
            }
            string strErrorMessage = "";

            foreach (ModelState modelState in ViewData.ModelState.Values)
            {
                foreach (ModelError error in modelState.Errors)
                {
                    strErrorMessage += error.ErrorMessage + "<br/>";
                }
            }
            return(Json(new { id = "0", error = strErrorMessage }));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Converts a string expression into a script object.
        /// </summary>
        private SObject ToScriptObject(string exp)
        {
            exp = exp.Trim();

            // This means it's either an indexer or an array
            if (exp.EndsWith("]"))
            {
                if (!(exp.StartsWith("[") && !exp.Remove(0, 1).Contains("["))) // When there's no "[" besides the start, and it starts with [, then it is an array. Otherwise, do real check.
                {
                    // It is possible that we are having a simple array declaration here.
                    // We check that by looking if we can find a "[" before the expression ends:

                    var depth                  = 0;
                    var index                  = exp.Length - 2;
                    var indexerStartIndex      = 0;
                    var foundIndexer           = false;
                    StringEscapeHelper escaper = new RightToLeftStringEscapeHelper(exp, index);

                    while (index > 0 && !foundIndexer)
                    {
                        var t = exp[index];
                        escaper.CheckStartAt(index);

                        if (!escaper.IsString)
                        {
                            if (t == ')' || t == '}' || t == ']')
                            {
                                depth++;
                            }
                            else if (t == '(' || t == '{')
                            {
                                depth--;
                            }
                            else if (t == '[')
                            {
                                if (depth == 0)
                                {
                                    if (index > 0)
                                    {
                                        indexerStartIndex = index;
                                        foundIndexer      = true;
                                    }
                                }
                                else
                                {
                                    depth--;
                                }
                            }
                        }

                        index--;
                    }

                    if (foundIndexer)
                    {
                        var indexerCode = exp.Substring(indexerStartIndex + 1, exp.Length - indexerStartIndex - 2);

                        var identifier = exp.Remove(indexerStartIndex);

                        var statementResult = ExecuteStatement(new ScriptStatement(indexerCode));
                        return(ToScriptObject(identifier).GetMember(this, statementResult, true));
                    }
                }
            }

            // Normal object return procedure:

            // Negative number:
            var isNegative = false;

            if (exp.StartsWith("-"))
            {
                exp        = exp.Remove(0, 1);
                isNegative = true;
            }

            double  dblResult;
            SObject returnObject;

            if (exp == SObject.LITERAL_NULL)
            {
                returnObject = Null;
            }
            else if (exp == SObject.LITERAL_UNDEFINED)
            {
                returnObject = Undefined;
            }
            else if (exp == SObject.LITERAL_BOOL_FALSE)
            {
                returnObject = CreateBool(false);
            }
            else if (exp == SObject.LITERAL_BOOL_TRUE)
            {
                returnObject = CreateBool(true);
            }
            else if (exp == SObject.LITERAL_NAN)
            {
                returnObject = CreateNumber(double.NaN);
            }
            else if (exp == SObject.LITERAL_THIS)
            {
                returnObject = Context.This;
            }
            else if (SNumber.TryParse(exp, out dblResult))
            {
                returnObject = CreateNumber(dblResult);
            }
            else if (exp.StartsWith("\"") && exp.EndsWith("\"") || exp.StartsWith("\'") && exp.EndsWith("\'"))
            {
                returnObject = CreateString(exp.Remove(exp.Length - 1, 1).Remove(0, 1), true, false);
            }
            else if (exp.StartsWith("$\"") && exp.EndsWith("\"") || exp.StartsWith("$\'") && exp.EndsWith("\'"))
            {
                returnObject = CreateString(exp.Remove(exp.Length - 1, 1).Remove(0, 2), true, true);
            }
            else if (exp.StartsWith("@\"") && exp.EndsWith("\"") || exp.StartsWith("@\'") && exp.EndsWith("\'"))
            {
                returnObject = CreateString(exp.Remove(exp.Length - 1, 1).Remove(0, 2), false, false);
            }
            else if (exp.StartsWith("{") && exp.EndsWith("}"))
            {
                returnObject = SProtoObject.Parse(this, exp);
            }
            else if (exp.StartsWith("[") && exp.EndsWith("]"))
            {
                returnObject = SArray.Parse(this, exp);
            }
            else if (exp.StartsWith("function") && Regex.IsMatch(exp, REGEX_FUNCTION))
            {
                returnObject = new SFunction(this, exp);
            }
            else if (Context.IsAPIUsing(exp))
            {
                returnObject = Context.GetAPIUsing(exp);
            }
            else if (Context.IsVariable(exp))
            {
                returnObject = Context.GetVariable(exp);
            }
            else if (Context.This.HasMember(this, exp))
            {
                returnObject = Context.This.GetMember(this, CreateString(exp), false);
            }
            else if (Context.IsPrototype(exp))
            {
                returnObject = Context.GetPrototype(exp);
            }
            else if (exp.StartsWith("new "))
            {
                returnObject = Context.CreateInstance(exp);
            }
            else if (exp.StartsWith(ObjectBuffer.OBJ_PREFIX))
            {
                var strId = exp.Remove(0, ObjectBuffer.OBJ_PREFIX.Length);
                var id    = 0;

                if (int.TryParse(strId, out id) && ObjectBuffer.HasObject(id))
                {
                    returnObject = (SObject)ObjectBuffer.GetObject(id);
                }
                else
                {
                    returnObject = ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_INVALID_TOKEN, exp);
                }
            }
            else
            {
                returnObject = ErrorHandler.ThrowError(ErrorType.ReferenceError, ErrorHandler.MESSAGE_REFERENCE_NOT_DEFINED, exp);
            }

            if (isNegative)
            {
                returnObject = ObjectOperators.NegateNumber(this, returnObject);
            }

            return(returnObject);
        }
Ejemplo n.º 17
0
        public ActionResult detail(int id, string strMessage = "")
        {
            try
            {
                string strError = "", strSuccess = "";
                if (!string.IsNullOrEmpty(strMessage))
                {
                    if (strMessage.Equals("bill1"))
                    {
                        strSuccess = "Xác nhận thanh toán thành công";
                    }
                    else if (strMessage.Equals("bill0"))
                    {
                        strError = "Xác nhận thanh toán thất bại";
                    }
                    else if (strMessage.Equals("delivery1"))
                    {
                        strSuccess = "Cập nhật thông tin giao hàng thành công";
                    }
                    else if (strMessage.Equals("delivery0"))
                    {
                        strError = "Cập nhật thông tin giao hàng thất bại";
                    }
                    else if (strMessage.Equals("update1"))
                    {
                        strSuccess = "Cập nhật thông tin đơn hàng thành công";
                    }
                    else if (strMessage.Equals("update0"))
                    {
                        strError = "Cập nhật thông tin đơn hàng thất bại";
                    }
                    else if (strMessage.Equals("addShippingAddress1"))
                    {
                        strSuccess = "Thêm mới địa chỉ giao hàng thành công";
                    }
                    else if (strMessage.Equals("addShippingAddress0"))
                    {
                        strError = "Thêm mới địa chỉ giao hàng thất bại";
                    }
                    else if (strMessage.Equals("editShippingAddress1"))
                    {
                        strSuccess = "Sửa địa chỉ giao hàng thành công";
                    }
                    else if (strMessage.Equals("editShippingAddress0"))
                    {
                        strError = "Sửa địa chỉ giao hàng thất bại";
                    }
                    else if (strMessage.Equals("editEmail1"))
                    {
                        strSuccess = "Sửa điạ chỉ email của khách hàng thành công";
                    }
                    else if (strMessage.Equals("editEmail1"))
                    {
                        strError = "Sửa điạ chỉ email của khách hàng thất bại";
                    }
                }
                ViewBag.strSuccess = strSuccess;
                ViewBag.strError   = strError;

                TblOrder order = orderService.GetByPrimaryKey(id);
                if (order == null)
                {
                    return(RedirectToAction("", "orders", new { strMessage = "notExist" }));
                }
                order.OrderName = "#" + (Common.BaseNumberOrder + order.Number).ToString() + " " + SDateTime.ToDateTime(order.CreatedDateTime);

                DetailOrderModel detailOrderModel = new DetailOrderModel();
                detailOrderModel.OrderID        = order.OrderID;
                detailOrderModel.CustomerEmail  = order.CustomerEmail;
                detailOrderModel.CustomerID     = order.CustomerID;
                detailOrderModel.Customer       = customerService.GetByPrimaryKey(SNumber.ToNumber(order.CustomerID));
                detailOrderModel.BillingStatus  = order.BillingStatus;
                detailOrderModel.ShippingStatus = order.ShippingStatus;
                detailOrderModel.TotalCount     = order.TotalCount;
                detailOrderModel.OrderName      = order.OrderName;
                detailOrderModel.OrderNote      = order.OrderNote;
                detailOrderModel.Tags           = order.Tags;
                detailOrderModel.ListTag        = tagService.GetByTableNameID((int)Common.TableName.TblOrder);

                detailOrderModel.BillingAddressID = SNumber.ToNumber(order.BillingAddressID);
                detailOrderModel.BillingAddress   = billingAddressService.GetByPrimaryKey(SNumber.ToNumber(order.BillingAddressID));
                if (detailOrderModel.BillingAddress != null)
                {
                    detailOrderModel.BillingAddress.Countries = countryService.GetAll();
                }

                detailOrderModel.ShippingAddressID = SNumber.ToNumber(order.ShippingAddressID);
                detailOrderModel.ShippingAddress   = shippingAddressService.GetByPrimaryKey(SNumber.ToNumber(order.ShippingAddressID));
                if (detailOrderModel.ShippingAddress == null)
                {
                    detailOrderModel.ShippingAddress = new ShippingAddress();
                }
                detailOrderModel.ShippingAddress.Countries = countryService.GetAll();

                if (order.OrderID > 0)
                {
                    List <LineItem> lineItems = lineItemService.GetByOrderID(order.OrderID);
                    foreach (var item in lineItems)
                    {
                        if (item.VariantName == "Default Title")
                        {
                            var thumb = ImageService.GetPathImageFirstOfProduct(item.ProductID);
                            item.ImageUrl = thumb;
                        }
                        else
                        {
                            Variant variant = variantService.GetByPrimaryKey(item.VariantID);
                            if (variant != null)
                            {
                                TblImage image = imageService.GetByPrimaryKey(variant.ImageID);
                                if (image != null)
                                {
                                    item.ImageUrl = image.ImageUrl;
                                }
                            }
                        }

                        if (item.ShippingStatus == null)
                        {
                            detailOrderModel.LineItemsPending.Add(item);
                        }
                        else
                        {
                            detailOrderModel.LineItemsPaid.Add(item);
                        }
                    }
                }
                return(View(detailOrderModel));
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                return(RedirectToAction("", "orders", new { strMessage = "notExist" }));
            }
        }
Ejemplo n.º 18
0
        private SObject ExecuteExecutable(ScriptStatement statement)
        {
            if (statement.IsCompoundStatement)
            {
                var processor = new ScriptProcessor(Context, GetLineNumber());

                // Remove { and }:
                var code = statement.Code.Remove(0, 1);
                code = code.Remove(code.Length - 1, 1);

                var returnObject = processor.Run(code);

                _breakIssued    = processor._breakIssued;
                _continueIssued = processor._continueIssued;
                _returnIssued   = processor._returnIssued;

                return(returnObject);
            }
            else
            {
                var exp = ResolveParentheses(statement.Code).Trim();

                #region QuickConvert

                // have quick conversions for small statements here
                // parameter statements are much faster that way:
                if (exp == SObject.LITERAL_BOOL_TRUE)
                {
                    return(CreateBool(true));
                }
                else if (exp == SObject.LITERAL_BOOL_FALSE)
                {
                    return(CreateBool(false));
                }
                else if (exp == SObject.LITERAL_UNDEFINED || exp == "")
                {
                    return(Undefined);
                }
                else if (exp == SObject.LITERAL_NULL)
                {
                    return(Null);
                }
                else if (exp.StartsWith("\"") && exp.EndsWith("\"") && !exp.Remove(exp.Length - 1, 1).Remove(0, 1).Contains("\""))
                {
                    return(CreateString(exp.Remove(exp.Length - 1, 1).Remove(0, 1)));
                }
                else if (exp.All(char.IsDigit))
                {
                    double num;
                    SNumber.TryParse(exp, out num);
                    return(CreateNumber(num));
                }

                #endregion

                if (exp.Contains("=>"))
                {
                    exp = EvaluateLambda(exp);
                }
                if (exp.Contains("."))
                {
                    exp = EvaluateOperator(exp, ".");
                }
                if (exp.Contains("++"))
                {
                    exp = EvaluateOperator(exp, "++");
                }
                if (exp.Contains("--"))
                {
                    exp = EvaluateOperator(exp, "--");
                }
                if (exp.Contains("!"))
                {
                    exp = EvaluateReverseBool(exp);
                }
                if (exp.Contains("**"))
                {
                    exp = EvaluateOperator(exp, "**");
                }
                if (exp.Contains("*"))
                {
                    exp = EvaluateOperator(exp, "*");
                }
                if (exp.Contains("/"))
                {
                    exp = EvaluateOperator(exp, "/");
                }
                if (exp.Contains("%"))
                {
                    exp = EvaluateOperator(exp, "%");
                }
                if (exp.Contains("+"))
                {
                    exp = EvaluateOperator(exp, "+");
                }
                if (exp.Contains("-"))
                {
                    exp = EvaluateOperator(exp, "-");
                }
                if (exp.Contains("<="))
                {
                    exp = EvaluateOperator(exp, "<=");
                }
                if (exp.Contains(">="))
                {
                    exp = EvaluateOperator(exp, ">=");
                }
                if (exp.Contains("<"))
                {
                    exp = EvaluateOperator(exp, "<");
                }
                if (exp.Contains(">"))
                {
                    exp = EvaluateOperator(exp, ">");
                }
                if (exp.Contains("==="))
                {
                    exp = EvaluateOperator(exp, "===");
                }
                if (exp.Contains("!=="))
                {
                    exp = EvaluateOperator(exp, "!==");
                }
                if (exp.Contains("=="))
                {
                    exp = EvaluateOperator(exp, "==");
                }
                if (exp.Contains("!="))
                {
                    exp = EvaluateOperator(exp, "!=");
                }
                if (exp.Contains("&&"))
                {
                    exp = EvaluateOperator(exp, "&&");
                }
                if (exp.Contains("||"))
                {
                    exp = EvaluateOperator(exp, "||");
                }

                return(ToScriptObject(exp));
            }
        }
Ejemplo n.º 19
0
 /// <summary>
 /// get name of customer from firstname and lastname
 /// </summary>
 /// <param name="customerID">id of customer</param>
 /// <returns>name of customer</returns>
 public static object GetCustomerName(int?customerID)
 {
     try
     {
         if (SNumber.ToNumber(customerID) <= 0)
         {
             return("");
         }
         IDbConnection connect  = new SqlConnection(Common.ConnectString);
         string        query    = "select * from Customer where CustomerID = " + SNumber.ToNumber(customerID);
         Customer      customer = connect.Query <Customer>(query).FirstOrDefault <Customer>();
         if (customer != null)
         {
             return(customer.CustomerFirstName + " " + customer.CustomerLastName);
         }
         return("");
     }
     catch (Exception ex)
     {
         LogService.WriteException(ex);
         return("");
     }
 }