Пример #1
0
        public static List <Models.ProductVariantOption> RemoveReferences(this List <Models.ProductVariantOption> list)
        {
            var newList = new List <Models.ProductVariantOption>();

            list.ForEach(item =>
            {
                var obj = new Models.ProductVariantOption();
                obj     = item.RemoveReference();
                newList.Add(obj);
            });
            return(newList);
        }
Пример #2
0
        private static Models.ProductVariantOption RemoveReference(this Models.ProductVariantOption item)
        {
            var obj = new Models.ProductVariantOption();

            if (item != null)
            {
                obj.Id                     = item.Id;
                obj.IsActive               = item.IsActive;
                obj.CategoryVariantId      = item.CategoryVariantId;
                obj.ProductVariantDetailId = item.ProductVariantDetailId;
                obj.VariantOptionId        = item.VariantOptionId;
            }
            return(obj);
        }
Пример #3
0
        public async Task <IActionResult> PostUser([FromBody] ProductModel product)
        {
            JsonResult response = null;

            product.UnitId = 2;
            //product table
            var pro = new Product();

            if (product.ShipmentVendor == true)
            {
                pro.ShipmentCost   = product.ShipmentCost;
                pro.ShipmentTime   = product.ShipmentTime;
                pro.ShipmentVendor = product.ShipmentVendor;
            }
            else
            {
                pro.ShipmentVendor = product.ShipmentVendor;
            }
            pro.CostPrice          = product.CostPrice;
            pro.VendorId           = product.VendorId;
            pro.Description        = product.Description;
            pro.Discount           = product.Discount;
            pro.IsActive           = true;
            pro.Name               = product.Name;
            pro.PriceAfterdiscount = product.PriceAfterDiscount;
            pro.ProductCategoryId  = product.ProductCategoryId;
            pro.ProductTags        = product.ProductTags;
            pro.SellingPrice       = product.SellingPrice;
            pro.UnitId             = product.UnitId;
            pro.VendorId           = product.VendorId;
            pro.IsEnable           = true;
            db.Products.Add(pro);
            try
            {
                db.SaveChanges();
                if (product.ProductTags != null)
                {
                    var      tagList    = new List <Tag>();
                    var      ProductTag = new List <ProductTag>();
                    var      checktag   = db.Tag.Where(x => x.IsActive == true).ToList();
                    var      tagFound   = new Tag();
                    string[] words      = product.ProductTags.Split(',');
                    foreach (var item in words)
                    {
                        tagFound = checktag.Where(x => x.Name.ToLower().Trim() == item.ToLower().Trim()).FirstOrDefault();
                        if (tagFound != null)
                        {
                            Tag tag = new Tag();
                            tag.Name     = item;
                            tag.IsActive = true;

                            db.Tag.Add(tag);
                            db.SaveChanges();
                            ProductTag productTag = new ProductTag();
                            productTag.TagId      = tag.Id;
                            productTag.IsActive   = true;
                            productTag.ProductId  = pro.Id;
                            productTag.IsApproved = true;
                            ProductTag.Add(productTag);
                        }
                    }
                    if (tagFound != null)
                    {
                        db.ProductTag.AddRange(ProductTag);
                        db.SaveChanges();
                    }
                }


                //---inserting variant details
                foreach (var item in product.ProductVariantDetails)
                {
                    var productDetailsData = new Models.ProductVariantDetail();
                    productDetailsData.ProductId  = pro.Id;
                    productDetailsData.InStock    = item.InStock;
                    productDetailsData.Price      = item.Price;
                    productDetailsData.IsActive   = true;
                    productDetailsData.IsDefault  = item.IsDefault;
                    productDetailsData.CostPrice  = item.CostPrice;
                    productDetailsData.Discount   = item.Discount;
                    productDetailsData.ProductSKU = item.ProductSKU;
                    productDetailsData.Lenght     = item.Lenght;
                    productDetailsData.Width      = item.Width;
                    productDetailsData.Height     = item.Height;

                    productDetailsData.Weight             = item.Weight;
                    productDetailsData.PriceAfterdiscount = item.PriceAfterdiscount;
                    db.ProductVariantDetails.Add(productDetailsData);
                    db.SaveChanges();

                    var specifications = new List <Models.ProductionSpecification>();
                    foreach (var specs in item.ProductSpecifications)
                    {
                        var specification = new Models.ProductionSpecification();
                        specification.HeadingName     = specs.HeadingName;
                        specification.Description     = specs.Description;
                        specification.IsActive        = true;
                        specification.VariantDetailId = productDetailsData.Id;
                        specification.ProductId       = pro.Id;
                        db.ProductionSpecifications.Add(specification);
                    }
                    db.SaveChanges();

                    //---inserting variant details imnage
                    if (item.ProductImages != null && item.ProductImages.Count > 0)
                    {
                        foreach (var pi in item.ProductImages)
                        {
                            var image = new ProductImage();
                            if (pi.ImagePath != null)
                            {
                                var imageResponse = await S3Service.UploadObject(pi.ImagePath);

                                response = new JsonResult(new Object());
                                if (imageResponse.Success)
                                {
                                    image.ImagePath = $"https://pistis.s3.us-east-2.amazonaws.com/{imageResponse.FileName}";
                                }
                            }

                            image.IsDefault = pi.IsDefault;
                            image.IsActive  = true;

                            image.ProductId = pro.Id;
                            image.ProductVariantDetailId = productDetailsData.Id;
                            db.ProductImages.Add(image);
                        }
                        db.SaveChanges();
                    }

                    if (item.ProductVariantOptions.Count > 0)
                    {
                        foreach (var option in item.ProductVariantOptions)
                        {
                            var varoption = new Models.ProductVariantOption();
                            varoption.CategoryVariantId      = option.CategoryVariantId;
                            varoption.ProductVariantDetailId = productDetailsData.Id;
                            varoption.VariantOptionId        = option.VariantOptionId;
                            varoption.IsActive = true;
                            db.ProductVariantOptions.Add(varoption);
                            db.SaveChanges();
                        }
                    }
                    db.SaveChanges();
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                return(null);
            }
        }