示例#1
0
        public ActionResult Overview(ProductGalleryVM obj)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    // TODO: Add insert logic here
                    obj = ExcuteActionCommonView(obj);
                    obj.SectionGalleries.PositionGalleryID = _repoPosition.GetItemByPosName(PositionTab.Overview).PositionGalleryID;
                    obj.SectionContents.PositionGalleryID  = obj.SectionGalleries.PositionGalleryID;
                    obj.ListSectionGalleries.Add(obj.SectionGalleries);

                    if (obj.CollectUrlGallery != null && obj.CollectUrlGallery.Any())
                    {
                        obj.ListSectionGalleries.Add(new Fly_SectionGallery()
                        {
                            CollectionImage = obj.CollectUrlGallery.Substring(0,
                                                                              obj.CollectUrlGallery.Length - 1),
                            CreatedOn         = DateTime.Now,
                            PositionGalleryID = _repoPosition.GetItemByPosName(PositionTab.Gallery).PositionGalleryID,
                            ProductID         = obj.SectionContents.ProductID
                        });
                    }


                    _repoSectionContent.Add(obj.SectionContents);
                    foreach (var listSectionGallery in obj.ListSectionGalleries)
                    {
                        _repoSectionGallery.Add(listSectionGallery);
                    }

                    scope.Complete();
                    scope.Dispose();
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                return(View(e.Message));
            }
        }
示例#2
0
        public ActionResult Edit(ProductVM obj)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    // get product table


                    //save product table
                    obj.Product.Published      = obj.isPublish;
                    obj.Product.Deleted        = obj.isDelete;
                    obj.Product.isAccessories  = obj.isAccessories;
                    obj.Product.UpdatedOn      = DateTime.Now;
                    obj.Product.ShowOnHomePage = obj.isHome;

                    // save productvariant table
                    obj.ProductVariant.IsShipEnabled  = obj.isShipEnabled;
                    obj.ProductVariant.IsFreeShipping = obj.isFreeShipping;
                    obj.ProductVariant.UpdatedOn      = DateTime.Now;
                    obj.ProductVariant.CallForPrice   = obj.isCallForPrice;
                    obj.ProductVariant.Deleted        = obj.Product.Deleted;
                    obj.ProductVariant.Name           = obj.Product.Name;
                    obj.ProductVariant.Description    = obj.Product.FullDescription;
                    obj.ProductVariant.Published      = obj.Product.Published;
                    obj.ProductVariant.isHot          = obj.isHot;
                    obj.ProductVariant.isNew          = obj.isNew;
                    obj.ProductVariant.isGift         = obj.isGift;

                    if (obj.indexDiscount > 0)
                    {
                        obj.ProductVariant.Fly_ProductVariant_Discount_Mapping.Add(new Fly_ProductVariant_Discount_Mapping
                        {
                            DiscountID        = obj.indexDiscount,
                            DiscountMappingID = obj.MappingDiscount.DiscountMappingID,
                            ProductVariantID  = obj.ProductVariant.ProductVariantId
                        });
                    }
                    obj.Product.Fly_ProductVariant.Add(obj.ProductVariant);
                    obj.Product.Fly_ProductLocalized.Add(obj.ProductLocalized);
                    obj.Product.Fly_ProductPicture.Add(obj.ProductPictures);

                    if (obj.indexCate > 0)
                    {
                        obj.Product.Fly_Product_Category_Mapping.Add(new Fly_Product_Category_Mapping
                        {
                            CategoryID        = obj.indexCate,
                            ProductCategoryID = obj.MappingCategories.ProductCategoryID
                        });
                    }

                    if (obj.indexManufacturer > 0)
                    {
                        obj.Product.Fly_Product_Manufacturer_Mapping.Add(new Fly_Product_Manufacturer_Mapping
                        {
                            ManufacturerID        = obj.indexManufacturer,
                            ProductManufacturerID = obj.MappingManufacturer.ProductManufacturerID
                        });
                    }

                    if (!obj.isNullData)
                    {
                        obj.SectionGalleries.PositionGalleryID = 5; // gallery
                        obj.SectionGalleries.CollectionImage   = obj.SectionGalleries.CollectionImage.Substring(0,
                                                                                                                obj.SectionGalleries.CollectionImage.Length - 1);
                        obj.SectionGalleries.CreatedOn = DateTime.Now;
                        obj.SectionGalleries.ProductID = obj.Product.ProductId;
                        _repoSectionGallery.Add(obj.SectionGalleries);
                    }

                    _repository.Edit(obj.Product);

                    if (obj.arrRelationProduct != null)
                    {
                        for (int i = 0; i < obj.arrRelationProduct.Split(',').Length; i++)
                        {
                            if (obj.arrRelationId != null && (obj.arrRelationId.Split(',')[i]) != null)
                            {
                                _repoRelatedProduct.Edit(new Fly_RelatedProduct()
                                {
                                    ProductID1       = obj.Product.ProductId,
                                    ProductID2       = int.Parse(obj.arrRelationProduct.Split(',')[i]),
                                    RelatedProductID = int.Parse(obj.arrRelationId.Split(',')[i])
                                });
                            }
                        }
                    }

                    scope.Complete();
                    scope.Dispose();
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                return(View(e));
            }
        }