Beispiel #1
0
        public ActionResult AddMasterProduct(FormCollection form)
        {
            var db = new FashionDb();
            var master = new MasterProduct()
                             {
                                 MasterId = form["masterId"],
                                 Label = form["label"],
                                 Supplier = form["supplier"],
                                 Name = form["name"],
                                 Type = form["productType"],
                                 MarkUp = Double.Parse(form["markUp"]),
                                 Season = form["season"],
                                 Cost = Double.Parse(form["Price"]),
                             };

            var dateAdded = DateTime.Now;

            var productsList = new List<Product>();
            for (int i = Int32.Parse(form["fromSize"]); i <= Int32.Parse(form["toSize"]); i += 2)
            {
                productsList.Add(new Product()
                                     {
                                         Color = form["color"],
                                         Currency = form["currency"],
                                         DateAdded = dateAdded,
                                         MasterId = master.MasterId,
                                         Size = i,
                                         Quantity = Int32.Parse(form["quantity"]),
                                         CodeName = String.Format("{0}-{1}-{2}",
                                            master.MasterId,
                                            i>=10?i.ToString():String.Format("0{0}",i),
                                            form["color"]),
                                         SellPrice = master.Cost*(master.MarkUp/100)
                                     });
            }
            master.Products = productsList;
            db.MasterProducts.Add(master);
            db.SaveChanges();

            return PartialView("_ProductsList",db.MasterProducts.Include("Products").Where(m=>m.MasterId==master.MasterId));
        }
Beispiel #2
0
        public ActionResult SaveMasterChanges(FormCollection form)
        {
            var db = new FashionDb();
            var label = form["label"];
            var type = form["productType"];
            var name = form["name"];
            var masterId = GetMasterId(form["masterId"]);

            var master = db.MasterProducts.Where(m => m.MasterId == masterId).Single();
            master.Label = label;
            master.Type = type;
            master.Name = name;
            db.SaveChanges();
            return PartialView("_ProductsList",db.MasterProducts.Include("Products"));
        }
Beispiel #3
0
 public ActionResult Search(string searchFor)
 {
     if(!String.IsNullOrEmpty(searchFor))
     {
         var db = new FashionDb();
         //ViewBag.Images = GetImages();
         GetIndexPageData();
         return View("Index", db.MasterProducts.Include("Products").Where(m => m.Name.Contains(searchFor) || m.Label.Contains(searchFor)));
     }
     return RedirectToAction("Index");
 }
Beispiel #4
0
        public void SaveChildChanges(FormCollection collection)
        {
            var db = new FashionDb();
            var id = Int32.Parse(collection["hdnChildId"]);
            var price = Double.Parse(collection["txtEditPrice"]);
            var q = Int32.Parse(collection["txtEditQuantity"]);

            var prod = db.Products.Where(p => p.ProductId == id).Single();
            prod.SellPrice = price;
            prod.Quantity = q;

            db.SaveChanges();
            return;
        }
Beispiel #5
0
        public ActionResult Index()
        {
            var db = new FashionDb();

            GetIndexPageData();

            ViewBag.Images = GetImages();

            return View(db.MasterProducts.Include("Products").OrderBy(m=>m.MasterId));
        }
Beispiel #6
0
        public JsonResult GetProductById(int id)
        {
            var db = new FashionDb();
            var prod = db.Products.Where(p => p.ProductId == id).Single();
            var master = db.MasterProducts.Where(m => m.MasterId == prod.MasterId).Single();
            return Json(new
                            {
                                prod.ProductId,
                                prod.SellPrice,
                                prod.MasterId,
                                prod.Currency,
                                prod.Color,
                                prod.Quantity,
                                prod.CodeName,
                                prod.MasterProduct.Name,
                                prod.MasterProduct.Label,
                                prod.MasterProduct.Supplier,
                                prod.MasterProduct.Type

                            }, JsonRequestBehavior.AllowGet);
        }
Beispiel #7
0
 public void DeleteProduct(int id)
 {
     var db = new FashionDb();
     var prod=db.Products.Where(p => p.ProductId == id).Single();
     var masterId = prod.MasterId;
     db.Products.Remove(prod);
     db.SaveChanges();
     if(db.Products.Where(p=>p.MasterId==masterId).Count()==0)
     {
         var master = db.MasterProducts.Where(m => m.MasterId == masterId).Single();
         db.MasterProducts.Remove(master);
     }
     db.SaveChanges();
 }
Beispiel #8
0
        public ActionResult DeleteMaster(FormCollection collection)
        {
            var db = new FashionDb();
            var masterId = GetMasterId(collection["masterIdDel"]);

            var master = db.MasterProducts.Where(m => m.MasterId == masterId).Single();
            db.MasterProducts.Remove(master);
            db.SaveChanges();
            return PartialView("_ProductsList", db.MasterProducts.Include("Products"));
        }