private void AjaxSaveData(SVData data) { CUSTOMRP.Model.SOURCEVIEWCOLUMN svc = null; foreach (SVCData r in data.items) { //v1.7.0 Ben 2017.08.21 - set the latest //svc = myColumns.Where(x => x.COLUMNNAME == r.COLUMNNAME).FirstOrDefault(); svc = myColumns.Where(x => x.COLUMNNAME == r.COLUMNNAME).OrderByDescending(x => x.ID).FirstOrDefault(); if (svc != null) { svc.DISPLAYNAME = r.DISPLAYNAME; svc.HIDDEN = Convert.ToBoolean(r.HIDDEN); } else { svc = new CUSTOMRP.Model.SOURCEVIEWCOLUMN(); svc.COLUMNNAME = r.COLUMNNAME; svc.DISPLAYNAME = r.DISPLAYNAME; svc.COLUMNTYPE = 1; svc.COLUMNCOMMENT = String.Empty; svc.HIDDEN = Convert.ToBoolean(r.HIDDEN); svc.DEFAULTDISPLAYNAME = String.Empty; myColumns.Add(svc); } } Session[strSessionViewNew_myColumns] = myColumns; }
private bool ProcessAjaxRequestParameters() { bool result = false; string p_strAction = (Request.Params["action"] ?? String.Empty).ToLower(); switch (p_strAction) { case "savedata": { string payload = Request.Params["payload"]; SVData data = null; try { data = this.GetSVData(payload); } catch (Exception ex) { AjaxShowError(ex.ToString()); return(false); } //v1.2.0 - Cheong - 2016/12/29 - Add validation against duplicate display name or colliding column name #region Display name validation foreach (SVCData r in data.items) { if (!String.IsNullOrEmpty(r.DISPLAYNAME)) { //v1.8.4 Ben 2018.05.23 - if duplicated one is hidden, allow save //if (data.items.Where(x => x.COLUMNNAME == r.DISPLAYNAME).Count() > 0) if (!Convert.ToBoolean(r.HIDDEN) && data.items.Where(x => x.COLUMNNAME == r.DISPLAYNAME && !Convert.ToBoolean(x.HIDDEN)).Count() > 0) { AjaxShowError(String.Format(AppNum.ErrorMsg.DisplayNameSameAsColumnName, r.DISPLAYNAME)); return(true); } //v1.8.4 Ben 2018.05.23 - if duplicated one is hidden, allow save //if (data.items.Where(x => x.DISPLAYNAME == r.DISPLAYNAME).Count() > 1) if (!Convert.ToBoolean(r.HIDDEN) && data.items.Where(x => x.DISPLAYNAME == r.DISPLAYNAME && !Convert.ToBoolean(x.HIDDEN)).Count() > 1) { AjaxShowError(String.Format(AppNum.ErrorMsg.DuplicateDisplayName, r.DISPLAYNAME)); return(true); } } } #endregion Display name validation try { this.AjaxSaveData(data); result = true; } catch (Exception ex) { AjaxShowError(ex.ToString()); return(false); } AjaxShowError(String.Empty); // OK } break; } return(result); }