public ActionResult LoadGrid(CMS_KeywordModels item) { try { var msg = ""; bool isCheck = true; if (item.KeySearch != null && item.KeySearch.Length > 0) { var temp = ListItem.Where(o => o.Trim() == item.KeySearch.Trim()).FirstOrDefault(); if (temp == null) { var result = _factory.CreateOrUpdate(item, ref msg); if (!result) { if (!string.IsNullOrEmpty(msg)) { ViewBag.DuplicateKeyword = msg; } else { isCheck = false; } } } else { ViewBag.DuplicateKeyword = "Duplicate Keyword!"; } } if (isCheck) { var model = _factory.GetList(); return(PartialView("_ListData", model)); } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } } catch (Exception e) { //_logger.Error("Keyword_Search: " + e); return(new HttpStatusCodeResult(400, e.Message)); } }
public ActionResult Index() { CMS_KeywordModels model = new CMS_KeywordModels(); List <SelectListItem> lstAcc = new List <SelectListItem>(); var lstAccount = _facAcc.GetList(); if (lstAccount != null && lstAccount.Any()) { lstAccount.ForEach(o => { lstAcc.Add(new SelectListItem { Value = o.Id, Text = o.Account }); }); } ViewBag.ListAccount = lstAcc; return(View(model)); }
public ActionResult AddKeywords(KeyOnGroupModels data) { CMS_EmployeeModels model = new CMS_EmployeeModels(); if (data.ListKeywordOnGroup != null && data.ListKeywordOnGroup.Count() > 0) { model.ListKeywords = new List <CMS_KeywordModels>(); } for (int i = 0; i < data.ListKeywordOnGroup.Count(); i++) { CMS_KeywordModels key = new CMS_KeywordModels(); key.OffSet = data.CurrentOffset; key.Id = data.ListKeywordOnGroup[i].KeyID; key.KeySearch = data.ListKeywordOnGroup[i].KeyName; key.Sequence = data.ListKeywordOnGroup[i].Seq; model.ListKeywords.Add(key); data.CurrentOffset++; } return(PartialView("_TabKeywords", model)); }
public bool CreateOrUpdate(CMS_KeywordModels model, ref string msg) { var result = true; using (var _db = new CMS_Context()) { using (var trans = _db.Database.BeginTransaction()) { m_Semaphore.WaitOne(); try { if (string.IsNullOrEmpty(model.Id)) { /* check dup old key */ var key = model.KeySearch; var key2 = ""; if (key[key.Length - 1] == '/') { key2 = key.Substring(0, key.Length - 1); } else { key2 = key + "/"; } var checkDup = _db.CMS_KeyWord.Where(o => o.KeyWord == key || o.KeyWord == key2).FirstOrDefault(); if (checkDup == null) { /* get current seq */ var curSeq = _db.CMS_KeyWord.OrderByDescending(o => o.Sequence).Select(o => o.Sequence).FirstOrDefault(); /* add new record */ var dateTimeNow = DateTime.Now; var newKey = new CMS_KeyWord() { ID = Guid.NewGuid().ToString(), KeyWord = model.KeySearch, Status = (byte)Commons.EStatus.Active, CreatedBy = model.CreatedBy, CreatedDate = dateTimeNow, UpdatedBy = model.CreatedBy, UpdatedDate = dateTimeNow, Sequence = ++curSeq, }; _db.CMS_KeyWord.Add(newKey); } else if (checkDup.Status != (byte)Commons.EStatus.Active) /* re-active old key */ { checkDup.Status = (byte)Commons.EStatus.Active; checkDup.UpdatedBy = model.CreatedBy; checkDup.UpdatedDate = DateTime.Now; } else /* duplicate key word */ { result = false; msg = "Duplicate key word."; } _db.SaveChanges(); trans.Commit(); } else { result = false; msg = "Unable to edit key word."; } } catch (Exception ex) { msg = "Check connection, please!"; result = false; trans.Rollback(); } finally { _db.Dispose(); m_Semaphore.Release(); } } } return(result); }
public ActionResult Index() { CMS_KeywordModels model = new CMS_KeywordModels(); return(View(model)); }