示例#1
0
        public List<PRODUCT> Search(PRODUCT Product, int PageSize, int PageIndex, out int TotalRecords, string OrderExp, SortDirection SortDirection)
        {
            // creating a graph with category and campaign to have the related campign for this product
            var result = Context.PRODUCT.Include("CATEGORY.CAMPAIGN").Include("PROD_IMAGES").AsQueryable();
            if (Product != null)
            {
                if (!String.IsNullOrWhiteSpace(Product.Name))
                {
                    result = result.Where(p => p.Name.Contains(Product.Name));
                }

                if (!String.IsNullOrWhiteSpace(Product.Description))
                {
                    result = result.Where(p => p.Description.Contains(Product.Description));
                }

                if (!String.IsNullOrWhiteSpace(Product.Code))
                {
                    result = result.Where(p => p.Code.Contains(Product.Code));
                }

                if (Product.CampaignID.HasValue)
                {
                    result = result.Where(p => p.CATEGORY.FirstOrDefault().CampaignID == Product.CampaignID);
                }

                if (Product.Closed.HasValue)
                {
                    result = result.Where(p => p.CATEGORY.FirstOrDefault().CAMPAIGN.Active == !Product.Closed.Value);
                }
            }
            TotalRecords = result.Count();
            if (!String.IsNullOrEmpty(OrderExp) && OrderExp.Equals("Remaining"))
            {
                if (SortDirection == SortDirection.Ascending)
                    result = result.OrderBy(c => c.PRODUCT_ATTRIBUTE.Select(p => p.Availability).Sum());
                else
                    result = result.OrderByDescending(c => c.PRODUCT_ATTRIBUTE.Select(p => p.Availability).Sum());
            }
            else
            {
                GenericSorterCaller<PRODUCT> sorter = new GenericSorterCaller<PRODUCT>();
                result = sorter.Sort(result, String.IsNullOrEmpty(OrderExp) ? "Name" : OrderExp, SortDirection);
            }
            result = result.Skip(PageIndex * PageSize).Take(PageSize);
            var SQL = (result as ObjectQuery).ToTraceString();

            return result.ToList();
        }
        private void FixupPRODUCT(PRODUCT previousValue)
        {
            if (previousValue != null && previousValue.PRODUCT_ATTRIBUTE.Contains(this))
            {
                previousValue.PRODUCT_ATTRIBUTE.Remove(this);
            }

            if (PRODUCT != null)
            {
                if (!PRODUCT.PRODUCT_ATTRIBUTE.Contains(this))
                {
                    PRODUCT.PRODUCT_ATTRIBUTE.Add(this);
                }
                if (ProductID != PRODUCT.ID)
                {
                    ProductID = PRODUCT.ID;
                }
            }
        }
 public void Update(PRODUCT Entity)
 {
     Update(Entity, true);
 }
 private bool setCategories(PRODUCT product)
 {
     CATEGORY cat;
     bool subCatChecked = false;
     foreach (TreeNode node in tvCategories.CheckedNodes)
     {
         if (node.Depth == 2)
         {
             subCatChecked = true;
         }
         cat = new CATEGORY() { ID = Int32.Parse(node.Value) };
         product.CATEGORY.Add(cat);
     }
     return subCatChecked;
 }
示例#5
0
 public void Delete(PRODUCT Product)
 {
     Context.PRODUCT.Attach(Product);
     Context.PRODUCT.DeleteObject(Product);
 }
 public void Insert(PRODUCT Entity)
 {
     _productDAO.Insert(Entity);
     Context.SaveChanges();
 }
        private void setImages(PRODUCT product, FZExcelProduct exProd, string encryptedCampId)
        {

            string startFolder = Configuration.ImagesUploadPath + "\\" + encryptedCampId;

            // Take a snapshot of the file system.
            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(startFolder);
            IEnumerable<System.IO.FileInfo> fileList = dir.GetFiles("*.*", System.IO.SearchOption.AllDirectories);

            //Create the query
            IEnumerable<System.IO.FileInfo> fileQuery =
                from file in fileList
                where file.Name.ToLower().Contains(exProd.Code.ToLower())
                orderby file.Name
                select file;

            //Execute the query
            PROD_IMAGES img;
            int count = 0;
            foreach (System.IO.FileInfo fi in fileQuery)
            {
                img = new PROD_IMAGES()
                {
                    ProductID = product.ID,
                    Image = "MED" + fi.Name,
                    LargeImage = fi.Name,
                    Thumbnail = "SMALL" + fi.Name,
                    Principal = false
                };

                if (count == 0)
                {
                    img.Principal = true;
                }
                fi.CopyTo(System.IO.Path.Combine(Configuration.ImagesUploadPath + fi.Name));
                // physical saving of all image versions
                GraphicsUtil.SaveProductImages(fi.Name, img.Principal.Value);

                InsertImage(img);
                Console.WriteLine(fi.FullName);
                count++;
            }
        }
        private void setAttributes(List<CATEGORY> categoriesList, PRODUCT product, FZExcelProduct exProd)
        {
            // TODO when different attributes used, this should be changed to be dynamic!
            int? sizeAttribute = categoriesList.FirstOrDefault().AttributeID;

            List<D_ATTRIBUTE_VALUE> attrValueList = _attributeDAO.GetAttributeValues(sizeAttribute.Value);
            PRODUCT_ATTRIBUTE prodAttr;
            int availability = 0;
            int attrValId = 0;

            // TODO this should be generalized for other attributes

            // XS size
            if (int.TryParse(exProd.SizeXS, out availability) && availability != 0)
            {
                attrValId = attrValueList.Where(a => a.Value.Equals("XS")).FirstOrDefault().ID;
                prodAttr = new PRODUCT_ATTRIBUTE()
                {
                    AttributeValueID = attrValId,
                    ProductID = product.ID,
                    Availability = availability,
                    Quantity = availability,
                };
                AddProductAttribute(prodAttr);
            }

            // S size
            if (int.TryParse(exProd.SizeS, out availability) && availability != 0)
            {
                attrValId = attrValueList.Where(a => a.Value.Equals("S")).FirstOrDefault().ID;
                prodAttr = new PRODUCT_ATTRIBUTE()
                {
                    AttributeValueID = attrValId,
                    ProductID = product.ID,
                    Availability = availability,
                    Quantity = availability,
                };
                AddProductAttribute(prodAttr);
            }

            // M size
            if (int.TryParse(exProd.SizeM, out availability) && availability != 0)
            {
                attrValId = attrValueList.Where(a => a.Value.Equals("M")).FirstOrDefault().ID;
                prodAttr = new PRODUCT_ATTRIBUTE()
                {
                    AttributeValueID = attrValId,
                    ProductID = product.ID,
                    Availability = availability,
                    Quantity = availability,
                };
                AddProductAttribute(prodAttr);
            }

            // L size
            if (int.TryParse(exProd.SizeL, out availability) && availability != 0)
            {
                attrValId = attrValueList.Where(a => a.Value.Equals("L")).FirstOrDefault().ID;
                prodAttr = new PRODUCT_ATTRIBUTE()
                {
                    AttributeValueID = attrValId,
                    ProductID = product.ID,
                    Availability = availability,
                    Quantity = availability,
                };
                AddProductAttribute(prodAttr);
            }

            // XL size
            if (int.TryParse(exProd.SizeXL, out availability) && availability != 0)
            {
                attrValId = attrValueList.Where(a => a.Value.Equals("XL")).FirstOrDefault().ID;
                prodAttr = new PRODUCT_ATTRIBUTE()
                {
                    AttributeValueID = attrValId,
                    ProductID = product.ID,
                    Availability = availability,
                    Quantity = availability,
                };
                AddProductAttribute(prodAttr);
            }

            // XXL size
            if (int.TryParse(exProd.SizeXXL, out availability) && availability != 0)
            {
                attrValId = attrValueList.Where(a => a.Value.Equals("XXL")).FirstOrDefault().ID;
                prodAttr = new PRODUCT_ATTRIBUTE()
                {
                    AttributeValueID = attrValId,
                    ProductID = product.ID,
                    Availability = availability,
                    Quantity = availability,
                };
                AddProductAttribute(prodAttr);
            }
        }
        public void ImportProducts(int CampaignId, string Path)
        {
            var productList = ProductExcelImporter.ReadProductExcel(Path);
            string encryptedCampId = FashionZone.BL.Util.Encryption.Encrypt(CampaignId.ToString());
            PRODUCT product;

            // preparing categories
            List<CATEGORY> categoriesList = _categoryDAO.GetCategoryListByCampaign(CampaignId);

            int? categoryParentF = null, categoryParentM = null;

            CATEGORY cat, categoryParent = null;
            categoryParent = categoriesList.Where(o => o.NameEng.Contains("Woman")).FirstOrDefault();
            if (categoryParent != null)
            {
                cat = new CATEGORY() { ID = categoryParent.ID };
                categoryParentF = categoryParent.ID;
            }

            categoryParent = categoriesList.Where(o => o.NameEng.Contains("Man")).FirstOrDefault();
            if (categoryParent != null)
            {
                cat = new CATEGORY() { ID = categoryParent.ID };
                categoryParentM = categoryParent.ID;
            }
            var query = (from c in categoriesList
                         select new { c.ID, c.Name, c.NameEng, c.ParentID }).ToList();

            foreach (FZExcelProduct exProd in productList)
            {
                product = new PRODUCT();
                product.Name = exProd.Title;
                product.Code = exProd.Code;
                decimal our, original, suppl = 0;
                if (Decimal.TryParse(exProd.Sell, out our))
                {
                    product.OurPrice = our;
                }
                if (Decimal.TryParse(exProd.Retail, out original))
                {
                    product.OriginalPrice = original;
                }

                if (Decimal.TryParse(exProd.Buy, out suppl))
                {
                    product.SupplierPrice = suppl;
                }

                product.Description = "Produkti <br /><br />" + exProd.Title + "<br /><br />" + exProd.Desc.Replace("\n", "<br />");

                setCategories(CampaignId, query, product, exProd.Category, exProd.Sex, categoryParentF, categoryParentM);

                // inserting the product entity, we are on a "transaction" so everything will
                // be rolled back in case the other statements aren't successful
                Insert(product);
                setAttributes(categoriesList, product, exProd);
                setImages(product, exProd, encryptedCampId);
            }
        }
示例#10
0
        private void setCampaignImg(PRODUCT product, CAMPAIGN campaign)
        {
            if (product.CampaignID.HasValue)
            {
                int campaignId = product.CampaignID.Value;
                if (campaign != null)
                {
                    CampaignID = campaign.ID;
                    imgBrandLogo.ImageUrl = Configuration.ImagesUploadPath + campaign.Logo;
                    imgBrandLogo.AlternateText = campaign.Name;

                    if (campaign.BRAND != null && campaign.BRAND.Shop.HasValue && campaign.BRAND.Shop.Value)
                    {
                        lblEstimatedDelivery.Text = Resources.Lang.ProductPickUpLabel + "<br />";
                        litEstimatedDates.Text = campaign.BRAND.Address;
                        lblInfo.Visible = true;
                        lblInfo.Text = "<br />" + Resources.Lang.ProductExclusivityLabel;
                    }
                    else
                    {
                        litEstimatedDates.Text = campaign.DeliveryStartDate.Value.ToString("dd/MM/yyyy") + " - " +
                            campaign.DeliveryEndDate.Value.ToString("dd/MM/yyyy");
                    }
                }
            }
        }
示例#11
0
 private void loadImages(PRODUCT product)
 {
     if (product.PROD_IMAGES != null && product.PROD_IMAGES.Count > 0)
     {
         PROD_IMAGES principalImage = product.PROD_IMAGES.Where(i => i.Principal.HasValue && i.Principal.Value).FirstOrDefault();
         imgProdBig.ImageUrl = Configuration.ImagesUploadPath + principalImage.Image;
         lnkImage.HRef = Configuration.ImagesUploadPath + principalImage.LargeImage;
         hdnPreviousImage.Value = principalImage.ID.ToString();
         rptImages.DataSource = product.PROD_IMAGES.OrderByDescending(i => i.Principal);
         rptImages.DataBind();
     }
 }
示例#12
0
 public void Insert(PRODUCT Product)
 {
     Context.PRODUCT.AddObject(Product);
     // Many to many relationship, the categories have to be treated 
     // differently, so no new category is created
     if (Product.CATEGORY != null && Product.CATEGORY.Count > 0)
     {
         foreach (CATEGORY cat in Product.CATEGORY)
         {
             Context.ObjectStateManager.ChangeObjectState(cat, EntityState.Unchanged);
         }
     }
 }
示例#13
0
 public void ChangeApproval(PRODUCT Product)
 {
     Context.PRODUCT.AddObject(Product);
     Context.ObjectStateManager.ChangeObjectState(Product, EntityState.Modified);
     var entry = Context.ObjectStateManager.GetObjectStateEntry(Product);
     entry.SetModifiedProperty("Approved");
     entry.SetModifiedProperty("ApprovedBy");
 }
示例#14
0
 public void DeleteById(int Id)
 {
     PRODUCT product = new PRODUCT() { ID = Id };
     Delete(product);
 }
示例#15
0
 public List<PROD_IMAGES> GetImages(PRODUCT Product)
 {
     throw new NotImplementedException();
 }
 public void Delete(PRODUCT Entity)
 {
     _productDAO.Delete(Entity);
     Context.SaveChanges();
 }
 public void ChangeApproval(PRODUCT Product)
 {
     _productDAO.ChangeApproval(Product);
 }
        private void FixupPRODUCT(PRODUCT previousValue)
        {
            if (previousValue != null && previousValue.PRODUCT_ATTRIBUTE.Contains(this))
            {
                previousValue.PRODUCT_ATTRIBUTE.Remove(this);
            }

            if (PRODUCT != null)
            {
                if (!PRODUCT.PRODUCT_ATTRIBUTE.Contains(this))
                {
                    PRODUCT.PRODUCT_ATTRIBUTE.Add(this);
                }
                if (ProductID != PRODUCT.ID)
                {
                    ProductID = PRODUCT.ID;
                }
            }
        }
        private void setCategories(int CampaignId, IEnumerable<dynamic> query, PRODUCT product, string Categories, string FMU,
            int? categoryParentF, int? categoryParentM)
        {
            CATEGORY cat;
            string[] cats = Categories.Split(',');
            int count = 0;

            foreach (string c in cats)
            {
                if (FMU == "F" || FMU == "U")
                {
                    // setting the macro category only once
                    if (count == 0)
                    {
                        if (categoryParentF.HasValue)
                        {
                            cat = Context.CATEGORY.Where(o => o.ID == categoryParentF.Value).First();
                            product.CATEGORY.Add(cat);
                        }
                    }
                    //setting the right category
                    var anonCat = query.Where(o => o.Name.Contains(c.Trim()) && o.ParentID == categoryParentF.Value).First();
                    int id = anonCat.ID;
                    if (anonCat != null)
                    {
                        cat = Context.CATEGORY.Where(o => o.ID == id).First();
                        cat.ParentID = categoryParentF;
                        product.CATEGORY.Add(cat);
                    }
                }
                else if (FMU == "M" || FMU == "U")
                {
                    // setting the macro category only once
                    if (count == 0)
                    {
                        if (categoryParentM.HasValue)
                        {
                            cat = Context.CATEGORY.Where(o => o.ID == categoryParentM.Value).First();
                            product.CATEGORY.Add(cat);
                        }
                    }

                    //setting the right category
                    var anonCat = query.Where(o => o.Name.Contains(c.Trim()) && o.ParentID == categoryParentM).First();
                    int id = anonCat.ID;
                    if (anonCat != null)
                    {
                        cat = Context.CATEGORY.Where(o => o.ID == id).First();
                        cat.ParentID = categoryParentM;
                        product.CATEGORY.Add(cat);
                    }
                }
                count++;
            }
        }
 private void loadCategories(PRODUCT product)
 {
     if (product.CATEGORY != null && product.CATEGORY.Count > 0)
     {
         populate(product.CampaignID.Value, product.Campaign, product.CATEGORY);
         chooseBrandCampPnl.Visible = false;
         tvCategories.Visible = true;
     }
 }
 public List<PROD_IMAGES> GetImages(PRODUCT Product)
 {
     return _productDAO.GetImages(Product);
 }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (tvCategories.Nodes.Count == 0 || tvCategories.CheckedNodes.Count == 0)
            {
                writeError("At least a category should be checked.");
                return;
            }

            if (!checkPrincipalImage() && chkApproved.Checked)
            {
                writeError("Approved product must contain a principal image.");
                return;
            }

            PRODUCT prod = new PRODUCT();
            prod.Name = txtName.Text;
            decimal our, original, suppl = 0;
            if (Decimal.TryParse(txtPrice.Text, out our))
            {
                prod.OurPrice = our;
            }
            if (Decimal.TryParse(txtOriginalPrice.Text, out original))
            {
                prod.OriginalPrice = original;
            }

            if (Decimal.TryParse(txtSupplierPrice.Text, out suppl))
            {
                prod.SupplierPrice = suppl;
            }

            prod.Description = txtDescription.Content;

            txtDiscount.Text = ((int)(((original - our) / original) * 100)).ToString();

            int id = 0;
            lblErrors.Visible = true;
            lblErrors.ForeColor = Color.Green;
            prod.Code = txtCode.Text;

            string operation = String.Empty;

            try
            {
                // sets checked category
                if (!setCategories(prod))
                {
                    writeError("At least one sub-category should be checked (ex. Woman->Jeans).");
                    return;
                }

                USER user = null;
                if (!String.IsNullOrEmpty(User.Identity.Name))
                {
                    user = ApplicationContext.Current.Users.GetByUserName(User.Identity.Name);
                }

                if (ProductID != 0)
                {
                    prod.ID = ProductID;
                    bool attached = false;

                    if (user != null)
                    {
                        bool? previousStatus = ApplicationContext.Current.Products.GetApprovalStatus(prod.ID);

                        if (chkApproved.Checked)
                        {
                            if (previousStatus == null || !previousStatus.Value)
                            {
                                if (user.RoleID <= 2)
                                {
                                    prod.Approved = true;
                                    prod.ApprovedBy = user.ID;
                                    ApplicationContext.Current.Products.ChangeApproval(prod);
                                    attached = true;
                                    txtApprover.Text = user.Login;
                                }
                            }
                        }
                        else
                        {
                            if (previousStatus.HasValue && previousStatus.Value)
                            {
                                if (user.RoleID <= 2)
                                {
                                    prod.Approved = false;
                                    ApplicationContext.Current.Products.ChangeApproval(prod);
                                    attached = true;
                                    txtApprover.Text = String.Empty;
                                }
                            }
                        }
                    }

                    ApplicationContext.Current.Products.Update(prod, !attached);
                    operation = "updated";
                }
                else
                {
                    if (user != null && chkApproved.Checked)
                    {
                        prod.Approved = true;
                        prod.ApprovedBy = user.ID;
                        txtApprover.Text = user.Login;
                    }
                    else
                    {
                        prod.Approved = false;
                    }

                    ApplicationContext.Current.Products.Insert(prod);
                    operation = "inserted";
                    ProductID = prod.ID;
                }

                updDiscountApprover.Update();
                saveAttributes(prod);

                ProductImageUpload upl;
                if (repeater.Items.Count > 0)
                {
                    foreach (RepeaterItem item in repeater.Items)
                    {
                        if (item.HasControls() && item.Controls[1] is ProductImageUpload)
                        {
                            upl = item.Controls[1] as ProductImageUpload;
                            if (upl.IsFormValid())
                            {
                                upl.ProdID = ProductID.ToString() ;
                                upl.Save();
                            }
                        }
                    }
                }

                lblErrors.Text = "Product " + operation + " correctly.";
                LinkButton lnkAddImage = lgnViewAddImage.FindControl("lnkAddImage") as LinkButton;
                if (lnkAddImage != null)
                {
                    lnkAddImage.Visible = true;
                }
                // deactivating campaign and brand ddls
                cddlBrand.Enabled = false;
                cddlCampain.Enabled = false;
                chooseBrandCampPnl.Visible = false;
                updPanelBrandCampaign.Update();

                UpdatePanel updPnlLnkAdd = lgnViewAddImage.FindControl("updPnlLnkAdd") as UpdatePanel;
                if (updPnlLnkAdd != null)
                {
                    updPnlLnkAdd.Update();
                }
            }
            // TODO handle situation with OptimisticConcurrencyException rethrown from BL
            catch (Exception ex)
            {
                // TODO log error
                writeError(ex.Message);
            }
        }
 public List<PRODUCT> Search(PRODUCT Product, int PageSize, int PageIndex, out int TotalRecords, string OrderExp, Util.SortDirection SortDirection)
 {
     return _productDAO.Search(Product, PageSize, PageIndex, out TotalRecords, OrderExp, SortDirection);
 }
        private void saveAttributes(PRODUCT product)
        {
            string prodAttrID, attrValID, availability;
            PRODUCT_ATTRIBUTE prodAttr;
            int id;
            foreach (ListViewDataItem item in lvAttributeValues.Items)
            {
                prodAttrID = attrValID = availability = String.Empty;

                prodAttrID = ((HiddenField)item.FindControl("prodAttrID")).Value;
                attrValID = ((HiddenField)item.FindControl("attrValID")).Value;
                availability = ((TextBox)item.FindControl("txtAvailability")).Text;

                id = 0;

                prodAttr = new PRODUCT_ATTRIBUTE();
                if (!String.IsNullOrEmpty(prodAttrID) && !String.IsNullOrEmpty(attrValID) && Int32.TryParse(prodAttrID, out id))
                {
                    // if availability is 0 and the attribute is never associated to this product, value is not considered
                    if (availability == "0" && id == 0)
                        continue;

                    ddlAttributes.Visible = false;
                    prodAttr.Availability = Int32.Parse(availability);
                    prodAttr.AttributeValueID = Int32.Parse(attrValID);
                    prodAttr.ProductID = product.ID;
                    // old version from previous retrieval
                    prodAttr.Version = (byte[])lvAttributeValues.DataKeys[item.DataItemIndex].Value;
                    if (id != 0)
                    {
                        // not new
                        prodAttr.ID = id;
                        ApplicationContext.Current.Products.UpdateProductAttribute(prodAttr);
                    }
                    else
                    {
                        // new, quantity is set only this time
                        prodAttr.Quantity = prodAttr.Availability;
                        ApplicationContext.Current.Products.AddProductAttribute(prodAttr);
                        ((HiddenField)item.FindControl("prodAttrID")).Value = prodAttr.ID.ToString();
                        ((Label)item.FindControl("lblQuantity")).Text = prodAttr.Quantity.ToString();
                    }
                }
            }

            // the list view is updated to reflect new versions after update
            List<PRODUCT_ATTRIBUTE> attributes = ApplicationContext.Current.Products.GetProductAttributes(ProductID);
            if (attributes.Count > 0)
            {
                populateAttributeValues(attributes.First().D_ATTRIBUTE_VALUE.AttributeID, attributes);
                updPanelAttributes.Update();
            }
        }
 public void Update(PRODUCT Entity, bool Attach = true)
 {
     using (var scope = new TransactionScope(TransactionScopeOption.Required,
         new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }))
     {
         // a transaction scope is required to rollback the executeStoreCommand done in productDAO.
         // the command is executed immediately so can't be handled by the default transactionality in EF
         // default isolation level is Serializable, which is too high for our needs so the normal read committed is set
         _productDAO.Update(Entity, Attach);
         Context.SaveChanges();
         scope.Complete();
     }
 }
示例#26
0
 public void Update(PRODUCT Product, bool Attach)
 {
     // first remove all categories
     Context.ExecuteStoreCommand("delete from product_category where ProductID = {0}", Product.ID);
     if (Attach)
     {
         Context.PRODUCT.AddObject(Product);
         Context.ObjectStateManager.ChangeObjectState(Product, EntityState.Modified);
     }
     // Many to many relationship, the categories have to be treated 
     // differently, so no new category is created
     if (Product.CATEGORY != null && Product.CATEGORY.Count > 0)
     {
         foreach (CATEGORY cat in Product.CATEGORY)
         {
             Context.ObjectStateManager.ChangeObjectState(cat, EntityState.Unchanged);
         }
     }
 }