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)); }
public ActionResult Create(MessageViewModel vmodel) { if (ModelState.IsValid) { //Check if min 1 value bool messageIsValid = TranslationBL.CheckIfMinOneValue(vmodel.MessagesTrans); if (messageIsValid) { //Check if Message exist by title before create bool titleExist = TranslationBL.CheckIfNameExist(vmodel.MessagesTrans); if (!titleExist) { MESSAGE message = new MESSAGE(); db.MESSAGEs.Add(message); int id = message.idMessage; //Check if isUniversal IList <MESSAGE_TRANSLATION> messagesT = TranslationBL.VerifyIsUniversal(vmodel.MessagesTrans, id); db.MESSAGE_TRANSLATIONs.AddRange(messagesT); db.SaveChanges(); return(RedirectToAction("Index")); } else { //to do --> match the error with the name that causes the error ViewBag.nameIsNotValid = "Le Titre existe déjà, veuillez saisir un autre nom!"; } } else { ViewBag.nameIsNotValid = "Veuillez saisir un titre et un message!"; } } vmodel.ListLang = LanguageBL.FindLanguageListWithoutUniversal(); return(View(vmodel)); }
public ActionResult Create(ShopViewModel vmodel) { if (ModelState.IsValid) { try { //if no image, assign default image string logo = vmodel.LogoShop; if (logo == null) { logo = "~/Content/image/logo_noImage.png"; } SHOP shop = new SHOP { logoShop = logo, phone = vmodel.Phone, email = vmodel.Email, zipCode = vmodel.ZipCode }; db.SHOPs.Add(shop); db.SaveChanges(); //Add Translation int id = shop.idShop; IList <SHOP_TRANSLATION> shopsT = TranslationBL.VerifyIsUniversal(vmodel.ShopsTrans, id); db.SHOP_TRANSLATIONs.AddRange(shopsT); db.SaveChanges(); return(RedirectToAction("Index")); } catch (DbEntityValidationException 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")); } 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")); } } vmodel.ListLang = LanguageBL.FindLanguageListWithoutUniversal(); return(View(vmodel)); }
public ActionResult Create(CategoryViewModel vmodel) { if (ModelState.IsValid) { //Check if nameHero have min 1 value IList <CATEGORY_TRANSLATION> catsT = vmodel.CategoriesTrans; bool nameCatIsValid = TranslationBL.CheckIfMinOneValued(catsT); if (nameCatIsValid) { //Check if Cat exist by nameCategory before create bool nameExist = TranslationBL.CheckIfNameExist(catsT); if (!nameExist) { CATEGORY cat = new CATEGORY { imageCat = vmodel.Image }; db.CATEGORYs.Add(cat); db.SaveChanges(); //Add Translation int id = cat.idCategory; IList <CATEGORY_TRANSLATION> newcatsT = TranslationBL.VerifyIsUniversal(catsT, id); db.CATEGORY_TRANSLATIONs.AddRange(newcatsT); db.SaveChanges(); if (vmodel.Parent != null) { SUBCATEGORY subCat = new SUBCATEGORY { parentCategory = vmodel.Parent.Value, childCategory = cat.idCategory }; db.SUBCATEGORYs.Add(subCat); db.SaveChanges(); } return(RedirectToAction("Index")); } else { //to do --> match the error with the name that causes the error ViewBag.nameIsNotValid = "Le nom existe déjà, veuillez saisir un autre nom!"; } } else { ViewBag.nameIsNotValid = "Veuillez saisir un nom!"; } } int lang = LanguageBL.CheckLanguageSession(); vmodel.ListLang = LanguageBL.FindLanguageListWithoutUniversal(); vmodel.Categories = db.SPP_CategoryTransDistinct(lang).ToList(); return(View(vmodel)); }
public ActionResult Edit(MessageViewModel vmodel) { if (ModelState.IsValid) { IList <MESSAGE_TRANSLATION> messagesT = TranslationBL.VerifyIsUniversal(vmodel.MessagesTrans, vmodel.IdMessage); foreach (var item in messagesT) { db.Entry(item).State = EntityState.Modified; } db.SaveChanges(); return(RedirectToAction("Index")); } vmodel.ListLang = LanguageBL.FindLanguageListWithoutUniversal(); return(View(vmodel)); }
public ActionResult Edit(ShopViewModel vmodel) { if (ModelState.IsValid) { db.Entry(vmodel.Shop).State = EntityState.Modified; IList <SHOP_TRANSLATION> shopsT = TranslationBL.VerifyIsUniversal(vmodel.ShopsTrans, vmodel.Shop.idShop); foreach (var item in shopsT) { db.Entry(item).State = EntityState.Modified; } db.SaveChanges(); return(RedirectToAction("Index")); } vmodel.ListLang = LanguageBL.FindLanguageListWithoutUniversal(); return(View(vmodel)); }
public ActionResult Edit(CategoryViewModel vmodel) { if (ModelState.IsValid) { db.Entry(vmodel.Cat).State = EntityState.Modified; IList <CATEGORY_TRANSLATION> catsT = TranslationBL.VerifyIsUniversal(vmodel.CategoriesTrans, vmodel.Cat.idCategory); foreach (var item in catsT) { db.Entry(item).State = EntityState.Modified; } db.SaveChanges(); return(RedirectToAction("Index")); } vmodel.ListLang = LanguageBL.FindLanguageListWithoutUniversal(); return(View(vmodel)); }
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)); }