public ActionResult editModule(TrainingCs newModule, string language) { if (language == null) { language = "ru"; } ViewBag.language = language; string Msg = "error"; Training editModule = db.Trainings.Find(newModule.ModuleId); try { newModule.Image = editModule.Image; HttpPostedFileBase file1 = Request.Files["img1"]; if (file1.FileName != "" && file1 != null) { string fullPath = Request.MapPath(editModule.Image); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } string ImageName = file1.FileName; editModule.Image = "~/Images/Training/Modules/" + DateTime.Now.Date.Year + DateTime.Now.Date.Month + DateTime.Now.Date.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + "_" + ImageName.Replace(" ", "_"); newModule.Image = editModule.Image; file1.SaveAs(HttpContext.Server.MapPath(editModule.Image)); } Training_Property Modules_PKZ = editModule.Training_Property.Where(e => e.lang == "kz").FirstOrDefault(); if (Modules_PKZ != null) { Modules_PKZ.Titile = newModule.NameKZ; } else { Training_Property newModules_PKZ = new Training_Property(); newModules_PKZ.lang = "kz"; newModules_PKZ.Titile = newModule.NameKZ; editModule.Training_Property.Add(newModules_PKZ); } Training_Property Modules_PRU = editModule.Training_Property.Where(e => e.lang == "ru").FirstOrDefault(); if (Modules_PRU != null) { Modules_PRU.Titile = newModule.NameRU; } Training_Property Modules_PUZ = editModule.Training_Property.Where(e => e.lang == "uz").FirstOrDefault(); if (Modules_PUZ != null) { Modules_PUZ.Titile = newModule.NameUZ; } else { Training_Property newModules_PUZ = new Training_Property(); newModules_PUZ.lang = "uz"; newModules_PUZ.Titile = newModule.NameUZ; editModule.Training_Property.Add(newModules_PUZ); } Training_Property Modules_PKR = editModule.Training_Property.Where(e => e.lang == "kr").FirstOrDefault(); if (Modules_PKR != null) { Modules_PKR.Titile = newModule.NameKR; } else { Training_Property newModules_PKR = new Training_Property(); newModules_PKR.lang = "kr"; newModules_PKR.Titile = newModule.NameKR; editModule.Training_Property.Add(newModules_PKR); } Training_Property Modules_PEN = editModule.Training_Property.Where(e => e.lang == "en").FirstOrDefault(); if (Modules_PEN != null) { Modules_PEN.Titile = newModule.NameEN; } else { Training_Property newModules_PEN = new Training_Property(); newModules_PEN.lang = "en"; newModules_PEN.Titile = newModule.NameEN; editModule.Training_Property.Add(newModules_PEN); } Training_Property Modules_PTR = editModule.Training_Property.Where(e => e.lang == "tr").FirstOrDefault(); if (Modules_PTR != null) { Modules_PTR.Titile = newModule.NameTR; } else { Training_Property newModules_PTR = new Training_Property(); newModules_PTR.lang = "tr"; newModules_PTR.Titile = newModule.NameTR; editModule.Training_Property.Add(newModules_PTR); } editModule.Enable = newModule.publish; editModule.XId = newModule.XId; db.SaveChanges(); Msg = "success"; ViewBag.EditModuleMsg = Msg; } catch { } return(View(newModule)); }
public async Task <ActionResult> createModule(TrainingCs newModule, string language) { if (language == null) { language = "ru"; } ViewBag.language = language; string Msg = "error"; Training createModule = new Training(); try { HttpPostedFileBase file1 = Request.Files["img1"]; if (file1.FileName != "" && file1 != null) { string ImageName = file1.FileName; createModule.Image = "~/Images/Training/Modules/" + DateTime.Now.Date.Year + DateTime.Now.Date.Month + DateTime.Now.Date.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + "_" + ImageName.Replace(" ", "_"); file1.SaveAs(HttpContext.Server.MapPath(createModule.Image)); } Training_Property Modules_PRU = new Training_Property(); Modules_PRU.lang = "ru"; Modules_PRU.Titile = newModule.NameRU; createModule.Training_Property.Add(Modules_PRU); if (newModule.NameKZ != null) { Training_Property Modules_PKZ = new Training_Property(); Modules_PKZ.lang = "kz"; Modules_PKZ.Titile = newModule.NameKZ; createModule.Training_Property.Add(Modules_PKZ); } if (newModule.NameUZ != null) { Training_Property Modules_PUZ = new Training_Property(); Modules_PUZ.lang = "uz"; Modules_PUZ.Titile = newModule.NameUZ; createModule.Training_Property.Add(Modules_PUZ); } if (newModule.NameKR != null) { Training_Property Modules_PKR = new Training_Property(); Modules_PKR.lang = "kr"; Modules_PKR.Titile = newModule.NameKR; createModule.Training_Property.Add(Modules_PKR); } if (newModule.NameEN != null) { Training_Property Modules_PEN = new Training_Property(); Modules_PEN.lang = "en"; Modules_PEN.Titile = newModule.NameEN; createModule.Training_Property.Add(Modules_PEN); } if (newModule.NameTR != null) { Training_Property Modules_PTR = new Training_Property(); Modules_PTR.lang = "tr"; Modules_PTR.Titile = newModule.NameTR; createModule.Training_Property.Add(Modules_PTR); } createModule.Enable = newModule.publish; createModule.XId = newModule.XId; db.Trainings.Add(createModule); await db.SaveChangesAsync(); Msg = "success"; } catch { } ViewBag.AddModuleMsg = Msg; return(View()); }
//: EDITMODULE --------------------------------------------------------------------------- public ActionResult editModule(int Id, string language) { if (language == null) { language = "ru"; } Training Training = db.Trainings.Find(Id); ViewBag.language = language; TrainingCs ModuleCs = new TrainingCs(); ModuleCs.ModuleId = Id; Training_Property Modules_PKZ = Training.Training_Property.Where(e => e.lang == "kz").FirstOrDefault(); if (Modules_PKZ != null) { ModuleCs.NameKZ = Modules_PKZ.Titile; } Training_Property Modules_PRU = Training.Training_Property.Where(e => e.lang == "ru").FirstOrDefault(); if (Modules_PRU != null) { ModuleCs.NameRU = Modules_PRU.Titile; } Training_Property Modules_PUZ = Training.Training_Property.Where(e => e.lang == "uz").FirstOrDefault(); if (Modules_PUZ != null) { ModuleCs.NameUZ = Modules_PUZ.Titile; } Training_Property Modules_PKR = Training.Training_Property.Where(e => e.lang == "kr").FirstOrDefault(); if (Modules_PKR != null) { ModuleCs.NameKR = Modules_PKR.Titile; } Training_Property Modules_PEN = Training.Training_Property.Where(e => e.lang == "en").FirstOrDefault(); if (Modules_PEN != null) { ModuleCs.NameEN = Modules_PEN.Titile; } Training_Property Modules_PTR = Training.Training_Property.Where(e => e.lang == "tr").FirstOrDefault(); if (Modules_PTR != null) { ModuleCs.NameTR = Modules_PTR.Titile; } ModuleCs.Image = Training.Image; ModuleCs.publish = Training.Enable; ModuleCs.XId = Training.XId; return(View(ModuleCs)); }