public void CloneDqMetaGroup(int currentId, List <country> listLanguage) { var index = 0; var proMaster = db.metagrups.FirstOrDefault(x => x.METAGROUPNO == currentId); if (proMaster != null) { foreach (var itemlang in listLanguage) { if (proMaster.CodeLanguage != itemlang.language.ToLower()) { var check = db.metagrups.FirstOrDefault(x => x.IdCurrentItem == currentId && x.CodeLanguage == itemlang.language.ToLower()); if (check == null) { var matagroup = new metagrup { PARENTNO = proMaster.PARENTNO, IsActive = proMaster.IsActive, CREATED = proMaster.CREATED, METAGROUPNAME = proMaster.METAGROUPNAME, METAGROUPCODE = proMaster.METAGROUPCODE, CodeLanguage = itemlang.language.ToLower(), IdCurrentItem = proMaster.METAGROUPNO }; db.metagrups.Add(matagroup); } } } db.SaveChanges(); } }
public JsonResult UpdateStatus(string status, string[] ids) { var _ids = ids.Select(t => int.Parse(t)).ToList(); bool _status = false; var msg = "Update Success"; try { var _items = db.metagrups.Where(x => _ids.Contains(x.METAGROUPNO)); foreach (var item in _items) { var list = db.metagrups.Where(x => x.IdCurrentItem == item.METAGROUPNO).ToList(); foreach (var item1 in list) { metagrup metagrup = db.metagrups.Find(item1.METAGROUPNO); metagrup.IsActive = false; db.Entry(metagrup).State = EntityState.Modified; } } db.SaveChanges(); _status = true; } catch (Exception) { msg = "Update Failed"; } return(Json(new { status = _status, mgs = msg })); }
public ActionResult CreateMetaGroup(AllModel model, HttpPostedFileBase[] inputfile) { if (model.tblMetaGroupArray != null) { var matagroup = new metagrup(); matagroup.PARENTNO = model.tblMetaGroup.PARENTNO; matagroup.IsActive = model.tblMetaGroup.IsActive; matagroup.CREATED = DateTime.Now; matagroup.METAGROUPNAME = model.tblMetaGroupArray[0].METAGROUPNAME; matagroup.METAGROUPCODE = model.tblMetaGroupArray[0].METAGROUPCODE; matagroup.CodeLanguage = "english"; db.metagrups.Add(matagroup); db.SaveChanges(); var updatematagroup = db.metagrups.Find(matagroup.METAGROUPNO); updatematagroup.IdCurrentItem = matagroup.METAGROUPNO; db.Entry(updatematagroup).State = EntityState.Modified; db.SaveChanges(); foreach (var item in model.tblMetaGroupArray.Skip(1).ToList()) { item.PARENTNO = model.tblMetaGroup.PARENTNO; item.IsActive = model.tblMetaGroup.IsActive; item.CREATED = DateTime.Now; item.IdCurrentItem = updatematagroup.IdCurrentItem; db.metagrups.Add(item); } db.SaveChanges(); if (inputfile != null) { for (int i = 0; i < inputfile.Length; i++) { if (inputfile[i] != null) { var fname = matagroup.IdCurrentItem + "." + inputfile[i].FileName.Split('.').Last(); string path = Server.MapPath("~/Content/MetagroupImage"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path + "/", fname); inputfile[i].SaveAs(path); } } } } return(RedirectToAction("IndexMetaGroup")); }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var list = db.metagrups.Where(x => x.IdCurrentItem == id).ToList(); foreach (var item in list) { metagrup metagrup = db.metagrups.Find(item.METAGROUPNO); metagrup.IsActive = false; db.Entry(metagrup).State = EntityState.Modified; } db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult EditMetaGroup(int code) { var listMasterMetaGroup = db.metagrups.Where(x => x.PARENTNO == 0).ToList(); listMasterMetaGroup.Insert(0, new metagrup { METAGROUPNO = 0, METAGROUPNAME = "Select Master Meta Group" }); ViewBag.ListMasterMetaGroup = listMasterMetaGroup; var proMaster = db.metagrups.FirstOrDefault(x => x.METAGROUPNO == code); var list = db.countries.Where(x => x.status == 1 && x.islanguage == 1).ToList(); ViewBag.ListCountry = list; foreach (var itemLang in list) { var pro = db.metagrups.FirstOrDefault(x => x.IdCurrentItem == code && x.CodeLanguage == itemLang.language.ToLower()); if (pro == null) { if (proMaster != null) { var tblItem = new metagrup(); tblItem.CREATED = proMaster.CREATED; tblItem.LASTCHANGE = proMaster.LASTCHANGE; tblItem.METAGROUPCODE = proMaster.METAGROUPCODE; tblItem.METAGROUPNAME = proMaster.METAGROUPNAME; tblItem.IsActive = proMaster.IsActive; tblItem.PARENTNO = proMaster.METAGROUPNO; tblItem.CodeLanguage = itemLang.language.ToLower(); tblItem.IdCurrentItem = proMaster.IdCurrentItem; db.metagrups.Add(tblItem); } } } db.SaveChanges(); var listCode = list.Select(y => y.language.ToLower()).ToList(); var item = db.metagrups.ToList().Where(x => x.IdCurrentItem == code && listCode.Contains(x.CodeLanguage)).ToList(); return(View(new AllModel { listMetaGroup = item, tblMetaGroup = proMaster })); }