/// <summary> /// Delete Variable /// </summary> /// <param name="id"></param> /// <param name="Model"></param> public void Delete(Guid id) { var languageID = TSMContext.CurrentLanguageID; Variable variable = VariableService.GetVariable(id, languageID); if (variable != null) { List <Choice> choicelist = new List <Choice>(); choicelist = variable.Choices; variable.Choices = new List <Choice>(); variable.LastModifiedBy = TSM.Model.TSMContext.CurrentUser.ID; variable.LastModifiedDate = DateTime.UtcNow; variable.IsActive = false; variable.IsDeleted = true; variable.DisplayOrder = null; string Name = variable.Variable_Languages[0].Name; string DisplayName = variable.Variable_Languages[0].DisplayName; string Description = variable.Variable_Languages[0].Description; variable.Variable_Languages = new List <Variable_Language>(); variable.Variable_Languages.Add(new Variable_Language { ID = variable.ID, LanguageID = TSMContext.CurrentLanguageID, Name = Name, DisplayName = DisplayName, Description = Description }); variable.Choices = choicelist; VariableService.Save(variable, TSM.Model.TSMContext.CurrentSiteLanguageID); DeleteFromXML(id); } }
/// <summary> /// Update Variable Order /// </summary> /// <param name="id"></param> /// <param name="Model"></param> public void UpdateOrder(Dictionary <string, string> stepsDictionary) { foreach (var stepsdictionary in stepsDictionary) { Guid Id; try { Id = new Guid(stepsdictionary.Key); } catch { Id = Guid.Empty; } var languageID = TSMContext.CurrentLanguageID; Variable variable = VariableService.GetVariable(Id, languageID); if (variable != null) { int output; int.TryParse(stepsdictionary.Value, out output); List <Choice> choicelist = new List <Choice>(); choicelist = variable.Choices; variable.Choices = new List <Choice>(); variable.LastModifiedBy = TSM.Model.TSMContext.CurrentUser.ID; variable.LastModifiedDate = DateTime.UtcNow; variable.DisplayOrder = output; string Name = variable.Variable_Languages[0].Name; string DisplayName = variable.Variable_Languages[0].DisplayName; string Description = variable.Variable_Languages[0].Description; variable.Variable_Languages = new List <Variable_Language>(); variable.Variable_Languages.Add(new Variable_Language { ID = variable.ID, LanguageID = TSMContext.CurrentLanguageID, Name = Name, DisplayName = DisplayName, Description = Description }); variable.Choices = choicelist; VariableService.Save(variable, TSM.Model.TSMContext.CurrentSiteLanguageID); } } }
/// <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); }