/// <summary> /// Save /// </summary> public Variable Save() { Variable variable = new Variable(); try { if (this.ID == Guid.Empty) { variable = new Variable(); variable.CreatedBy = TSM.Model.TSMContext.CurrentUser.ID; variable.CreatedDate = DateTime.UtcNow; int count = VariableService.VariableCount(); variable.DisplayOrder = count + 1; } else { variable = this.GetVariableFull(this.ID, TSM.Model.TSMContext.CurrentLanguageID); variable.LastModifiedBy = TSM.Model.TSMContext.CurrentUser.ID; variable.LastModifiedDate = DateTime.UtcNow; } //FOR Variable variable.Type = this.Variable_Type; variable.VariableCategory = this.VariableCategory; variable.ShowInAdvancedSearchFilter = this.Is_AdvanceSearchFilter; variable.ShowInDetailPage = this.ShowInDetailPage; variable.ShowInReport = this.ShowInReport; variable.IsSytemDefined = this.IsSystemDefined; variable.FilterHeading = this.FilterHeading; variable.IsActive = this.IsActive; variable.IsMandatory = this.IsMandetory; variable.Variable_Languages.Add(new Variable_Language { ID = this.ID, LanguageID = TSM.Model.TSMContext.CurrentLanguageID, Name = this.Variable_Name, DisplayName = this.Variable_DisplayName, Description = this.Variable_Description }); List <Choice> clist = new List <Choice>(); if (this.ManageChoiceForString != null) { if (this.ManageChoiceForString.Count > 0) { Choice_Language clang = new Choice_Language(); Choice choice = new Choice(); Char[] split = new Char[1]; split[0] = '/'; for (int i = 0; i < this.ManageChoiceForString.Count; i++) { string[] str = this.ManageChoiceForString[i].Split(split, StringSplitOptions.RemoveEmptyEntries); choice = new Choice(); clang = new Choice_Language(); choice.Choice_Languages = new List <Choice_Language>(); if (str[0] != "00000000-0000-0000-0000-000000000000") { choice.ID = new Guid(str[0]); clang.ID = new Guid(str[0]); } choice.VariableID = variable.ID; choice.IsActive = variable.IsActive; clang.Name = str[1]; clang.LanguageID = TSM.Model.TSMContext.CurrentLanguageID; clang.ID = choice.ID; choice.Choice_Languages.Add(clang); clist.Add(choice); } } variable.Choices = clist; } VariableService.Save(variable, TSM.Model.TSMContext.CurrentSiteLanguageID); try { bool isactive = variable.IsActive; if (!isactive) { DeleteFromXML(variable.ID); } else { UpdateXML(); } } catch (Exception ee) { ErrorLog.WriteLog("ManageVariable", "SaveXML", ee, ""); } if (this.ID != Guid.Empty) { this.ManageChoices = new List <SelectListItem>(); variable.Choices.Select(c => c.Choice_Languages).ToList().ForEach(cl => this.ManageChoices.Add( new SelectListItem() { Value = (cl[0].ID == null ? null : (cl[0].ID.ToString() + "/" + cl[0].Name.ToString())), Text = cl[0].Name, Selected = true })); this.ManageChoiceForString = null; } } catch (Exception ex) { ErrorLog.WriteLog("ManageUserModel", "Save", ex, ""); } return(variable); }