public static MATERIAL ObtenerMaterial(TAT001Entities db, string user_id, string material_id) { string spras_id = ObtenerSprasId(db, user_id); MATERIAL material = db.MATERIALs.Where(x => x.ID == material_id).FirstOrDefault(); if (material.MATERIALTs.Any(x => x.SPRAS == spras_id)) { MATERIALT mt = material.MATERIALTs.First(x => x.SPRAS == spras_id); material.MAKTX = mt.MAKTX; material.MAKTG = mt.MAKTG; } return(material); }
public ActionResult Edit([Bind(Include = "ID,MTART,MATKL_ID,MAKTX,MAKTG,MEINS,PUNIT,ACTIVO,CTGR,BRAND,MATERIALGP_ID,EN,ES,PT")] MATERIAL mATERIAL, FormCollection collection) { if (ModelState.IsValid) { MATERIAL mATERIAL1 = db.MATERIALs.Find(mATERIAL.ID); var materialtextos = db.MATERIALTs.Where(t => t.MATERIAL_ID == mATERIAL.ID).ToList(); db.MATERIALTs.RemoveRange(materialtextos); List <MATERIALT> ListmATERIALTs = new List <MATERIALT>(); if (collection.AllKeys.Contains("EN")) { if (!String.IsNullOrEmpty(collection["EN"])) { MATERIALT m = new MATERIALT { SPRAS = "EN", MATERIAL_ID = mATERIAL.ID, MAKTX = collection["EN"], MAKTG = collection["EN"].ToUpper() }; ListmATERIALTs.Add(m); } if (mATERIAL1.MAKTX != collection["EN"]) { mATERIAL1.MAKTX = collection["EN"]; mATERIAL1.MAKTG = Convert.ToString(collection["EN"]).ToUpper(); } } if (collection.AllKeys.Contains("ES") && !String.IsNullOrEmpty(collection["ES"])) { MATERIALT m = new MATERIALT { SPRAS = "ES", MATERIAL_ID = mATERIAL.ID, MAKTX = collection["ES"], MAKTG = Convert.ToString(collection["ES"]).ToUpper() }; ListmATERIALTs.Add(m); } if (collection.AllKeys.Contains("PT") && !String.IsNullOrEmpty(collection["PT"])) { MATERIALT m = new MATERIALT { SPRAS = "PT", MATERIAL_ID = mATERIAL.ID, MAKTX = collection["PT"], MAKTG = Convert.ToString(collection["PT"]).ToUpper() }; ListmATERIALTs.Add(m); } db.MATERIALTs.AddRange(ListmATERIALTs); db.SaveChanges(); return(RedirectToAction("Index")); } int pagina_id = 664; //ID EN BASE DE DATOS FnCommon.ObtenerConfPage(db, pagina_id, User.Identity.Name, this.ControllerContext.Controller); return(View(mATERIAL)); }