public ActionResult AddOrEdit(int id = 0)
        {
            if (id == 0)
            {
                using (ELaundryDBEntities db = new ELaundryDBEntities())
                {
                    ViewBag.Categories = db.tblCategories.ToList();

                    return(View(new GarmentViewModel()));
                }
            }
            else
            {
                using (ELaundryDBEntities db = new ELaundryDBEntities())
                {
                    ViewBag.Categories = db.tblCategories.ToList();
                    GarmentViewModel sub = new GarmentViewModel();
                    var menu             = db.tblGarments.Where(x => x.GarmentId == id).FirstOrDefault();
                    sub.GarmentId   = menu.GarmentId;
                    sub.GarmentName = menu.GarmentName;
                    sub.UnitPrice   = menu.UnitPrice;
                    sub.CategoryId  = menu.tblCategory.CategoryId;
                    return(View(sub));
                }
            }
        }
 public ActionResult AddOrEdit(GarmentViewModel sm)
 {
     using (ELaundryDBEntities db = new ELaundryDBEntities())
     {
         if (sm.GarmentId == 0)
         {
             tblGarment tb = new tblGarment();
             tb.CategoryId  = sm.CategoryId;
             tb.GarmentName = sm.GarmentName;
             tb.UnitPrice   = sm.UnitPrice;
             db.tblGarments.Add(tb);
             db.SaveChanges();
             return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             tblGarment tbm = db.tblGarments.Where(m => m.GarmentId == sm.GarmentId).FirstOrDefault();
             tbm.CategoryId  = sm.CategoryId;
             tbm.GarmentName = sm.GarmentName;
             tbm.UnitPrice   = sm.UnitPrice;
             db.SaveChanges();
             return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
        internal Product ConvertToProduct(string condition = null, int?userDemand = null, decimal?Duration = null, char?dlmtr = null)
        {
            decimal?price   = null;
            var     prodDet = "";
            var     config  = new MapperConfiguration(cfg => { });
            var     mapper  = new Mapper(config);

            if (this.ProductType.Equals("FoodAndBeverageItems"))
            {
                FoodAndBeveragesViewModel food = mapper.Map <FoodAndBeveragesViewModel>(this.ProductDetail);
                prodDet = food.ConvertToItem(dlmtr);
                price   = food.UnitPriceItemCalculation();
            }
            else if (this.ProductType.Equals("MaterialItems"))
            {
                MaterialViewModel materi = mapper.Map <MaterialViewModel>(this.ProductDetail);
                prodDet = materi.ConvertToItem(dlmtr);
                price   = materi.UnitPriceItemCalculation();
            }
            else if (this.ProductType.Equals("GarmentItems"))
            {
                GarmentViewModel garment = mapper.Map <GarmentViewModel>(this.ProductDetail);
                prodDet = garment.ConvertToItem(dlmtr);
                price   = garment.UnitPriceItemCalculation();
            }
            else if (this.ProductType.Equals("TransportationServices"))
            {
                TransportationServicesViewModel trans = mapper.Map <TransportationServicesViewModel>(this.ProductDetail);
                prodDet = trans.ConvertToServ(dlmtr);
                price   = trans.RateCostCalculation(condition, userDemand, Duration);
            }
            else if (this.ProductType.Equals("TelecommunicationServices"))
            {
                TelecomunicationServicesViewModel tele = mapper.Map <TelecomunicationServicesViewModel>(this.ProductDetail);
                prodDet = tele.ConvertToServ(dlmtr);
                price   = tele.RateCostCalculation(condition, userDemand, Duration);
            }
            else
            {
                price         = 0;
                ProductDetail = null;
            }
            return(new Product()
            {
                ProductID = this.ProductID,
                ProductName = this.ProductName,
                SupplierID = this.SupplierID,
                CategoryID = this.CategoryID,
                QuantityPerUnit = this.QuantityPerUnit,
                UnitPrice = price,
                UnitsInStock = this.UnitsInStock,
                UnitsOnOrder = this.UnitsOnOrder,
                ReorderLevel = this.ReorderLevel,
                Discontinued = this.Discontinued,
                ProductType = this.ProductType,
                ProductDetail = prodDet
            });
        }
        public NewProductViewModel(Product product, char?dlmtr)
        {
            ProductID       = product.ProductID;
            ProductName     = product.ProductName;
            SupplierID      = product.SupplierID;
            CategoryID      = product.CategoryID;
            QuantityPerUnit = product.QuantityPerUnit;
            UnitPrice       = product.UnitPrice;
            UnitsInStock    = product.UnitsInStock;
            UnitsOnOrder    = product.UnitsOnOrder;
            ReorderLevel    = product.ReorderLevel;
            Discontinued    = product.Discontinued;
            ProductType     = product.ProductType;
            if (ProductType != null)
            {
                switch (ProductType)
                {
                case "FoodAndBeverageItems":
                    FoodAndBeveragesViewModel food = new FoodAndBeveragesViewModel(product, dlmtr);
                    ProductDetail = food.FromItemToDict();
                    break;

                case "GarmentItems":
                    GarmentViewModel garment = new GarmentViewModel(product, dlmtr);
                    ProductDetail = garment.FromItemToDict();
                    break;

                case "MaterialItems":
                    MaterialViewModel materi = new MaterialViewModel(product, dlmtr);
                    ProductDetail = materi.FromItemToDict();
                    break;

                case "TransportationServices":
                    TransportationServicesViewModel trans = new TransportationServicesViewModel(product, dlmtr);
                    ProductDetail = trans.FromServToDict();
                    break;

                case "TelecommunicationServices":
                    TelecomunicationServicesViewModel telecomunication = new TelecomunicationServicesViewModel(product, dlmtr);
                    ProductDetail = telecomunication.FromServToDict();
                    break;

                default:
                    ProductDetail = null;
                    break;
                }
            }
            else
            {
                ProductDetail = null;
            }
        }
        public Product ConvertToProduct2(string condition = null, int?userDemand = null, decimal?Duration = null)
        {
            decimal?price = null;
            Dictionary <string, object> prodDict  = new Dictionary <string, object>();
            ProductValidator            validator = new ProductValidator();
            var config = new MapperConfiguration(cfg => { });
            var mapper = new Mapper(config);

            if (this.ProductType.Equals("FoodAndBeverageItems"))
            {
                FoodBevItemViewModel food = mapper.Map <FoodBevItemViewModel>(this.ProductDetail);
                prodDict = food.fromItemToDict();
                price    = food.unitPriceItemCalculation();
                validator.isValidProductDetail(prodDict, ProductType);
            }
            else if (this.ProductType.Equals("MaterialItems"))
            {
                MaterialViewModel materi = mapper.Map <MaterialViewModel>(this.ProductDetail);
                prodDict = materi.fromItemToDict();
                price    = materi.unitPriceItemCalculation();
                validator.isValidProductDetail(prodDict, ProductType);
            }
            else if (this.ProductType.Equals("GarmentItems"))
            {
                GarmentViewModel garment = mapper.Map <GarmentViewModel>(this.ProductDetail);
                prodDict = garment.fromItemToDict();
                price    = garment.unitPriceItemCalculation();
                validator.isValidProductDetail(prodDict, ProductType);
            }
            else if (this.ProductType.Equals("TransportationServices"))
            {
                TransportationServicesViewModel trans = mapper.Map <TransportationServicesViewModel>(this.ProductDetail);
                prodDict = trans.fromServToDict();
                price    = trans.RateCostCalculation(condition, userDemand, Duration);
                validator.isValidProductDetail(prodDict, ProductType);
            }
            else if (this.ProductType.Equals("TelecommunicationServices"))
            {
                TelecomunicationServiceViewModel tele = mapper.Map <TelecomunicationServiceViewModel>(this.ProductDetail);
                prodDict = tele.fromServToDict();
                price    = tele.RateCostCalculation(condition, userDemand, Duration);
                validator.isValidProductDetail(prodDict, ProductType);
            }
            else
            {
                price         = 0;
                ProductDetail = null;
            }

            if (validator.isValidProductDetail(prodDict, ProductType))
            {
                return(new Product()
                {
                    ProductID = this.ProductID,
                    ProductName = this.ProductName,
                    SupplierID = this.SupplierID,
                    CategoryID = this.CategoryID,
                    QuantityPerUnit = this.QuantityPerUnit,
                    UnitPrice = price,
                    UnitsInStock = this.UnitsInStock,
                    UnitsOnOrder = this.UnitsOnOrder,
                    ReorderLevel = this.ReorderLevel,
                    Discontinued = this.Discontinued,
                    ProductType = this.ProductType,
                    ProductDetail = prodDict.ToString()
                });
            }
            else
            {
                return(null);
            }
        }