Ejemplo n.º 1
0
        public ActionResult Edit(ProductViewModel vmodel)
        {
            if (ModelState.IsValid)
            {
                db.Entry(vmodel.Product).State = EntityState.Modified;
                //db.SaveChanges();
                IList <PRODUCT_TRANSLATION> productsT = TranslationBL.VerifyIsUniversal(vmodel.ProductsTrans, vmodel.IdProduct);
                foreach (var item in vmodel.ProductsTrans)
                {
                    db.Entry(item).State = EntityState.Modified;
                }
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            bool isUniversal = false;

            if (vmodel.ProductsTrans.Count() == 1)
            {
                isUniversal = true;
            }
            ViewBag.isUniversal = isUniversal;
            int lang  = LanguageBL.CheckLanguageSession();
            int ULang = LanguageBL.FindUniversalId();

            vmodel.ListLang        = LanguageBL.FindLanguageListWithoutUniversal();
            vmodel.CategoriesTrans = db.CATEGORY_TRANSLATIONs.Where(c => c.languageId == lang || c.languageId == ULang).ToList();
            vmodel.Ages            = db.AGEs.ToList();
            vmodel.Brands          = db.BRANDs.ToList();
            vmodel.HeroesTrans     = db.HERO_TRANSLATIONs.Where(c => c.languageId == lang || c.languageId == ULang).ToList();
            vmodel.Vats            = db.VATs.ToList();

            return(View(vmodel));
        }
Ejemplo n.º 2
0
        // GET: Products/Edit/5
        //[Authorize(Roles = "admin")]
        //[Authorize(Roles = "manager")]
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PRODUCT pRODUCT = db.PRODUCTs.Find(id);

            if (pRODUCT == null)
            {
                return(HttpNotFound());
            }
            var translation = db.PRODUCT_TRANSLATIONs.Where(pt => pt.productId == id).ToList();

            ProductViewModel vm          = new ProductViewModel();
            bool             isUniversal = false;

            if (translation.Count() == 1)
            {
                isUniversal = true;
            }
            ViewBag.isUniversal = isUniversal;

            vm.Product = pRODUCT;

            vm.IdProduct    = pRODUCT.idProduct;
            vm.Barcode      = pRODUCT.barcode;
            vm.Price        = pRODUCT.salesPrice;
            vm.Discount     = pRODUCT.discountRate;
            vm.ImageProduct = pRODUCT.imageProduct;
            vm.Category     = pRODUCT.categoryId.ToString();
            vm.Age          = pRODUCT.ageId.ToString();
            vm.Brand        = pRODUCT.brandId.ToString();
            vm.Hero         = pRODUCT.heroId.ToString();

            vm.ProductsTrans = translation;

            int lang  = LanguageBL.CheckLanguageSession();
            int ULang = LanguageBL.FindUniversalId();

            vm.ListLang        = LanguageBL.FindLanguageListWithoutUniversal();
            vm.CategoriesTrans = db.CATEGORY_TRANSLATIONs.Where(c => c.languageId == lang || c.languageId == ULang).ToList();
            vm.Ages            = db.AGEs.ToList();
            vm.Brands          = db.BRANDs.ToList();
            vm.HeroesTrans     = db.HERO_TRANSLATIONs.Where(c => c.languageId == lang || c.languageId == ULang).ToList();
            vm.Vats            = db.VATs.ToList();
            return(View(vm));
        }
Ejemplo n.º 3
0
        // GET: Products/Create
        //[Authorize(Roles = "admin")]
        //[Authorize(Roles = "manager")]
        public ActionResult Create()
        {
            int lang            = LanguageBL.CheckLanguageSession();
            int ULang           = LanguageBL.FindUniversalId();
            ProductViewModel vm = new ProductViewModel
            {
                ListLang        = LanguageBL.FindLanguageListWithoutUniversal(),
                CategoriesTrans = db.CATEGORY_TRANSLATIONs.Where(c => c.languageId == lang || c.languageId == ULang).ToList(),
                Ages            = db.AGEs.ToList(),
                Brands          = db.BRANDs.ToList(),
                HeroesTrans     = db.HERO_TRANSLATIONs.Where(c => c.languageId == lang || c.languageId == ULang).ToList(),
                Vats            = db.VATs.ToList()
            };

            return(View(vm));
        }
Ejemplo n.º 4
0
        public ActionResult Create(ProductViewModel vmodel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    //if no image, assign default image
                    string img = vmodel.ImageProduct;
                    if (img == null)
                    {
                        img = "~/Content/image/logo_noImage.png";
                    }
                    // check if hero is null
                    int?hero = null;
                    if (vmodel.Hero != null)
                    {
                        hero = int.Parse(vmodel.Hero);
                    }
                    PRODUCT product = new PRODUCT
                    {
                        barcode      = vmodel.Barcode,
                        salesPrice   = vmodel.Price,
                        discountRate = vmodel.Discount,
                        imageProduct = img,
                        categoryId   = int.Parse(vmodel.Category),
                        ageId        = int.Parse(vmodel.Age),
                        brandId      = int.Parse(vmodel.Brand),
                        heroId       = hero,
                        vatId        = int.Parse(vmodel.Vat)
                    };
                    db.PRODUCTs.Add(product);
                    db.SaveChanges();

                    //Add Translation
                    int id = product.idProduct;
                    IList <PRODUCT_TRANSLATION> productsT = TranslationBL.VerifyIsUniversal(vmodel.ProductsTrans, id);

                    db.PRODUCT_TRANSLATIONs.AddRange(productsT);
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    //to do insert to log file
                    var e1 = ex.GetBaseException(); // --> log
                    var e4 = ex.Message;            // --> log
                    var e5 = ex.Source;             // --> log
                    var e8 = ex.GetType();          // --> log
                    var e9 = ex.GetType().Name;     // --> log
                    return(View("Error"));
                }
            }
            int lang  = LanguageBL.CheckLanguageSession();
            int ULang = LanguageBL.FindUniversalId();

            vmodel.ListLang        = LanguageBL.FindLanguageListWithoutUniversal();
            vmodel.CategoriesTrans = db.CATEGORY_TRANSLATIONs.Where(c => c.languageId == lang || c.languageId == ULang).ToList();
            vmodel.Ages            = db.AGEs.ToList();
            vmodel.Brands          = db.BRANDs.ToList();
            vmodel.HeroesTrans     = db.HERO_TRANSLATIONs.Where(c => c.languageId == lang || c.languageId == ULang).ToList();
            vmodel.Vats            = db.VATs.ToList();
            return(View(vmodel));
        }