public int GetPrice(ProductMap product, int quantity)
        {
            int price = 0;

            switch (product)
            {
            case (ProductMap.A):
                price = PromotionA.A;
                break;

            case (ProductMap.B):
                price = PromotionB.B;
                break;

            case (ProductMap.C):
                price = PromotionCD.C;
                break;

            case (ProductMap.D):
                price = PromotionCD.D;
                break;

            default:
                break;
            }

            return(quantity * price);
        }
Exemple #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            ProductMap productMap = db.ProductMaps.Find(id);

            db.ProductMaps.Remove(productMap);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public DTOModelMapperTest()
        {
            var resolver = new Mock<IMapperResolver>();
            mapper = new SmartMapper<DTO, Model>(resolver.Object);

            var productMap = new ProductMap();
            var userMap = new UserMap();

            resolver.Setup(x => x.Resolve(typeof (IMapper<DTOProduct, Model>))).Returns(productMap);
            resolver.Setup(x => x.Resolve(typeof (IMapper<DTOUser, Model>))).Returns(userMap);
        }
Exemple #4
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            ProductMap.Map(modelBuilder.Entity <Product>());
            ServiceMap.Map(modelBuilder.Entity <Service>());

            TransactionMap.Map(modelBuilder.Entity <Transaction>());
            ItemTransactionMap.Map(modelBuilder.Entity <ItemTransaction>());
            ItemTransactionChargeMap.Map(modelBuilder.Entity <ItemTransactionCharge>());
        }
Exemple #5
0
 public ActionResult Edit([Bind(Include = "Map_id,Product_id,Variant_id,Product_price")] ProductMap productMap)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productMap).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Product_id = new SelectList(db.Products, "Product_id", "Product_name", productMap.Product_id);
     ViewBag.Variant_id = new SelectList(db.Variants, "Variant_id", "Variant1", productMap.Variant_id);
     return(View(productMap));
 }
        public ActionResult Create([Bind(Include = "ProductId,Name,Price,Type,Brand")] ProductVM productVM)
        {
            var product = ProductMap.ProductVMToProduct(productVM);

            if (ModelState.IsValid)
            {
                productsRepositories.Add(product);
                return(RedirectToAction("Index"));
            }

            return(View(productVM));
        }
        // GET: Products
        public ActionResult Index()
        {
            var productsVM = new List <ProductVM>();

            foreach (var product in productsRepositories.GetAll())
            {
                var productVM = ProductMap.ProductToProductVM(product);

                productsVM.Add(productVM);
            }

            return(View(productsVM));
        }
Exemple #8
0
        // GET: ProductMaps/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductMap productMap = db.ProductMaps.Find(id);

            if (productMap == null)
            {
                return(HttpNotFound());
            }
            return(View(productMap));
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.Configure <MongoDbSettings>(options => Configuration.GetSection("MongoDbDatabaseSettings").Bind(options));
            services.AddSingleton <MongoDbSettings>(sp => sp.GetRequiredService <IOptions <MongoDbSettings> >().Value);

            services.AddScoped <EcommDbContext, EcommDbContext>();

            services.AddTransient <IProductRepository, ProductRepository>();
            services.AddTransient <IProductHandler, ProductHandler>();

            ProductMap.Configure();
        }
        }//CheckCustomer

        //-------------------------------------------------------------------------------------------------------//

        /// <summary>
        /// Checks whether product exists.
        /// </summary>
        /// <param name="prodCode">Product Code</param>
        /// <returns>This Product or blank Product.</returns>
        public Product CheckProduct(string prodCode)
        {
            Product product;

            if (ProductMap.ContainsKey(prodCode))
            {
                product = ProductMap[prodCode];
            }
            else
            {
                product = new Product();
            }//else

            return(product);
        }//CheckProduct
Exemple #11
0
        // GET: ProductMaps/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductMap productMap = db.ProductMaps.Find(id);

            if (productMap == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Product_id = new SelectList(db.Products, "Product_id", "Product_name", productMap.Product_id);
            ViewBag.Variant_id = new SelectList(db.Variants, "Variant_id", "Variant1", productMap.Variant_id);
            return(View(productMap));
        }
        // GET: Products/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Product product = productsRepositories.GetById(id.Value);

            if (product == null)
            {
                return(HttpNotFound());
            }

            var productVM = ProductMap.ProductToProductVM(product);

            return(View(productVM));
        }
Exemple #13
0
        // GET: ProductMaps/Details/5
        public ActionResult Details(int?id)
        {
            if (Session["UserId"] == null)
            {
                return(View("Unauthorized"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductMap productMap = db.ProductMaps.Find(id);

            if (productMap == null)
            {
                return(HttpNotFound());
            }
            return(View(productMap));
        }
Exemple #14
0
        public async Task <IActionResult> OnPostAsync(int venueId)
        {
            if (!ModelState.IsValid)
            {
                await FetchData(venueId).ConfigureAwait(false);

                return(this.TurboPage());
            }

            if (!await FetchData(venueId).ConfigureAwait(false))
            {
                return(RedirectToPage("/Index"));
            }

            var productIds         = Input.ProductIds.Select(id => int.Parse(id)).ToList();
            var selectedProductIds = productIds
                                     .Where(id => ProductMap.ContainsKey(id))
                                     .Select(id => ProductMap[id])
                                     .Where(product => product.VenueId == venueId)
                                     .Select(product => product.ProductId)
                                     .ToList();

            var result = await menus.CreateFullMenu(new NewMenu
            {
                Products        = selectedProductIds,
                MenuName        = Input.MenuName,
                MenuDescription = Input.MenuDescription,
                VenueId         = venueId
            }).ConfigureAwait(false);

            if (result.IsSuccess)
            {
                return(this.RedirectToPage("/Menu", new
                {
                    menuId = result.Value
                }));
            }

            return(this.Page());
        }
Exemple #15
0
        public IHttpActionResult ProductGroupSubmit(ProductGroupSearchModel model)
        {
            try
            {
                if (model.Id <= 0)
                {
                    var ProductGroupExist = _productGroupService.GetProductGroups(x => x.Name == model.Name && x.CompanyId == model.CompanyId).FirstOrDefault();

                    if (ProductGroupExist != null)
                    {
                        return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, "Group name already exist.")));
                    }

                    var productGroup = new ProductGroup();
                    productGroup.Name        = model.Name;
                    productGroup.Description = model.Description;
                    productGroup.SRate       = model.SRate;
                    productGroup.Code        = GetCode(model.CompanyId);
                    productGroup.IsActive    = true;
                    productGroup.IsAdd       = true;
                    productGroup.IsUpdate    = true;
                    productGroup.IsDelete    = true;
                    productGroup.IsContinue  = true;
                    productGroup.CreatedDate = DateTime.Now;
                    productGroup.CompanyId   = model.CompanyId;

                    _productGroupService.InsertProductGroup(productGroup);


                    foreach (var item in model.Products)
                    {
                        ProductMap map = new ProductMap()
                        {
                            ProductGroupId = productGroup.Id,
                            ProductId      = item.Id
                        };

                        _productMapService.InsertProductMap(map);
                    }


                    string jsonData = JsonConvert.SerializeObject(productGroup);



                    SqlParameter[] param =
                    {
                        new SqlParameter("@logData",    jsonData),
                        new SqlParameter("@clientId",   model.CompanyId),
                        new SqlParameter("@userId",     model.CreatedBy),
                        new SqlParameter("@type",       "Insert"),
                        new SqlParameter("@action",     "ProductGroupSubmit"),
                        new SqlParameter("@controller", "ProductGroup"),
                    };

                    _spService.ExcuteSpAnonmious("prc_insertLog", param, 1);
                }
                else
                {
                    var productGroup = _productGroupService.GetProductGroupById(model.Id);

                    if (productGroup != null)
                    {
                        productGroup.Name         = model.Name;
                        productGroup.Description  = model.Description;
                        productGroup.SRate        = model.SRate;
                        productGroup.ModifiedBy   = model.CreatedBy;
                        productGroup.ModifiedDate = DateTime.Now;
                        _productGroupService.UpdateProductGroup(productGroup);



                        var maps = _productMapService.GetProductMaps(x => x.ProductGroupId == productGroup.Id).ToList();

                        foreach (var item in maps)
                        {
                            _productMapService.DeleteProductMap(item);
                        }

                        foreach (var item in model.Products)
                        {
                            ProductMap map = new ProductMap()
                            {
                                ProductGroupId = productGroup.Id,
                                ProductId      = item.Id
                            };

                            _productMapService.InsertProductMap(map);
                        }



                        string jsonData = JsonConvert.SerializeObject(model);

                        SqlParameter[] param =
                        {
                            new SqlParameter("@logData",    jsonData),
                            new SqlParameter("@clientId",   model.CompanyId),
                            new SqlParameter("@userId",     model.CreatedBy),
                            new SqlParameter("@type",       "Update"),
                            new SqlParameter("@action",     "ProductGroupSubmit"),
                            new SqlParameter("@controller", "ProductGroup"),
                        };

                        _spService.ExcuteSpAnonmious("prc_insertLog", param, 1);
                    }
                    else
                    {
                        return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, "Test does not exist, please try again!")));
                    }
                }

                return(Ok(true));
            }
            catch (Exception ex)
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)));
            }
        }
 /// <inheritdoc />
 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
     ProductMap.Register(modelBuilder);
 }
Exemple #17
0
        public virtual void DoImport(webModel.CsvImportConfiguration configuration, ImportNotification notification)
        {
            var csvProducts = new List <coreModel.CatalogProduct>();
            var catalog     = _catalogService.GetById(configuration.CatalogId);

            try
            {
                using (var reader = new CsvReader(new StreamReader(_blobStorageProvider.OpenReadOnly(configuration.FileUrl))))
                {
                    reader.Configuration.Delimiter = configuration.Delimiter;
                    var initialized = false;
                    while (reader.Read())
                    {
                        if (!initialized)
                        {
                            //Notification
                            notification.Description = "Configuration...";
                            _notifier.Upsert(notification);

                            //set import configuration based on mapping info
                            var productMap = new ProductMap(reader.FieldHeaders, configuration, catalog);
                            reader.Configuration.RegisterClassMap(productMap);
                            initialized = true;

                            //Notification
                            notification.Description = "Reading products from csv...";
                            _notifier.Upsert(notification);
                        }

                        try
                        {
                            var csvProduct = reader.GetRecord <coreModel.CatalogProduct>();
                            csvProducts.Add(csvProduct);
                        }
                        catch (Exception ex)
                        {
                            var error = ex.Message;
                            if (ex.Data.Contains("CsvHelper"))
                            {
                                error += ex.Data["CsvHelper"];
                            }
                            notification.ErrorCount++;
                            notification.Errors.Add(error);
                        }
                    }
                }

                SaveCategoryTree(catalog, csvProducts, notification);
                SaveProducts(catalog, csvProducts, notification);
            }
            catch (Exception ex)
            {
                notification.Description = "Export error";
                notification.ErrorCount++;
                notification.Errors.Add(ex.ToString());
            }
            finally
            {
                notification.Finished    = DateTime.UtcNow;
                notification.Description = "Import finished" + (notification.Errors.Any() ? " with errors" : " successfully");
                _notifier.Upsert(notification);
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="objProductMap"></param>
 public void InsertProductMap(ProductMap objProductMap)
 {
     _roleRepository.Add(objProductMap);
     _unitOfWork.Commit();
 }
        public void ImportProductsTest()
        {
            var catalogId = "57b2ed0c42a94eb88f1c7b97afaf183d";

            var product = new coreModel.CatalogProduct();
            //Auto detect mapping configuration
            var mappingConfiguration = new string[] { "Name", "Code", "Category", "Reviews" }.Select(x => new webModel.CsvImportMappingItem {
                EntityColumnName = x
            }).ToArray();

            DoAutoMapping(mappingConfiguration);
            //Edit mapping configuration in UI

            var reviewMappingItem = mappingConfiguration.First(x => x.EntityColumnName == "Reviews");

            reviewMappingItem.CsvColumnName = "Reviews";
            //Start import
            //read objects from csv use mapping configuration
            var csvProducts = new List <CatalogProduct>();

            using (var reader = new CsvReader(new StreamReader(@"c:\Projects\VCF\vc-community\PLATFORM\Modules\Catalog\VirtoCommerce.CatalogModule.Test\products.csv")))
            {
                reader.Configuration.Delimiter = ";";
                var initialized = false;
                while (reader.Read())
                {
                    if (!initialized)
                    {
                        var productMap = new ProductMap(reader.FieldHeaders, mappingConfiguration);
                        reader.Configuration.RegisterClassMap(productMap);
                        initialized = true;
                    }

                    var csvProduct = reader.GetRecord <coreModel.CatalogProduct>();
                    csvProducts.Add(csvProduct);
                }
            };

            var categories = new List <coreModel.Category>();

            //project product information to category structure (categories, properties etc)
            foreach (var csvProduct in csvProducts)
            {
                var productCategoryNames = csvProduct.Category.Path.Split('/');
                ICollection <coreModel.Category> levelCategories = categories;
                foreach (var categoryName in productCategoryNames)
                {
                    var category = levelCategories.FirstOrDefault(x => x.Name == categoryName);
                    if (category == null)
                    {
                        category = new coreModel.Category()
                        {
                            Name = categoryName, Code = categoryName.GenerateSlug()
                        };
                        category.CatalogId = catalogId;
                        category.Children  = new List <coreModel.Category>();
                        levelCategories.Add(category);
                    }
                    csvProduct.Category = category;
                    levelCategories     = category.Children;
                }
            }

            var categoryService = GetCategoryService();
            var newCategories   = new List <coreModel.Category>();

            //save to db
            //Categories
            foreach (var category in categories)
            {
                var newCategory = categoryService.Create(category);
                newCategories.Add(newCategory);
                foreach (var childCategory in category.Traverse(x => x.Children))
                {
                    newCategory = categoryService.Create(childCategory);
                    newCategories.Add(newCategory);
                }
            }
            var productService = GetItemService();

            //Products
            foreach (var csvProduct in csvProducts)
            {
                var sameProduct = csvProducts.FirstOrDefault(x => x.Name == csvProduct.Name && !x.IsTransient());
                if (sameProduct != null)
                {
                    //Detect variation
                    csvProduct.MainProductId = sameProduct.Id;
                }
                var category = newCategories.FirstOrDefault(x => x.Code == csvProduct.Category.Code);
                csvProduct.CategoryId = category.Id;
                csvProduct.CatalogId  = catalogId;
                var newProduct = productService.Create(csvProduct);
                csvProduct.Id = newProduct.Id;
            }
        }
Exemple #20
0
 public static void Configure()
 {
     ProductMap.Configure();
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="objProductMap"></param>
 public void DeleteProductMap(ProductMap objProductMap)
 {
     _roleRepository.Delete(objProductMap);
     _unitOfWork.Commit();
 }