public ListItem(Data.ListItem data, bool addChildren = true, bool addParent = false) : this(data.ListItemId, data.LastUpdateTimestamp.Ticks) { string fullListName = null; Data.ListItem list = data.Parent; while (list != null) { fullListName = string.Concat(list.Name, string.IsNullOrEmpty(fullListName) ? string.Empty : string.Concat("/", fullListName)); list = list.Parent; } FullListName = fullListName; ListName = data.Parent == null ? null : data.Parent.Name; ListValue = data.Parent == null ? null : data.Parent.Value; ListDescription = data.Parent == null ? null : data.Parent.Description; Name = data.Name; Description = data.Description; Code = data.Code; Value = data.Value; Status = data.Status.Name; SortOrder = data.SortOrder; LastUpdateTimestamp = data.LastUpdateTimestamp; LastUpdateAccount = string.Format("{0} {1}", data.LastUpdateAccount.FirstName, data.LastUpdateAccount.LastName); ParentId = data.ParentId; if (addParent && data.Parent != null) { this.Parent = new ListItem(data.Parent, addParent: true); } if (addChildren) { Children = data.Children.Select(l => new ListItem(l)).ToList(); } }
public ScaleScore(Data.ListItem data) : base(data.ListItemId, data.LastUpdateTimestamp.Ticks) { ScaleScoreId = data.ListItemId; Description = data.Description; Name = data.Name; SortOrder = data.SortOrder; ScoreValues = data.Children.Where(li => li.Value != null).ToList().Select(x => new ScoreValue(x)).ToList(); }
public Models.UpdateResult SaveListItem(Models.ListItem model) { return(Execute(context => { Guid lastUpdateAccountId = context.Accounts.Single(a => a.Username == model.LastUpdateUsername).AccountId; Data.ListItem listItem; if (!string.IsNullOrEmpty(model.ID)) { Guid listItemId = BaseModel.DecryptId(model.ID); listItem = context.ListItems.Single(li => li.ListItemId == listItemId); if (listItem.LastUpdateTimestamp.Ticks != model.Age) { return new UpdateResult(UpdateResult.ResultType.DataChanged); } } else { listItem = new Data.ListItem { ParentId = BaseModel.DecryptNullableId(model.ParentID), StatusId = GetListItem("Status", "Active").GUID }; context.ListItems.Add(listItem); } if (!string.IsNullOrWhiteSpace(model.Name)) { listItem.Name = model.Name; } listItem.Description = model.Description; listItem.SortOrder = model.SortOrder; listItem.Code = model.Code; listItem.Value = model.Value; WriteAudit(context, lastUpdateAccountId); listItem.LastUpdateAccountId = lastUpdateAccountId; listItem.LastUpdateTimestamp = DateTime.Now; context.SaveChanges(); return new UpdateResult(true); })); }
internal Models.ListItem GetListItem(params string[] names) { Guid?parentId = null; return(Execute(context => { Data.ListItem li = null; foreach (string name in names) { li = context.ListItems.Single(lix => lix.ParentId == parentId && lix.Name == name); if (li == null) { return null; } parentId = li.ListItemId; } return new Models.ListItem(li); })); }
public Models.Client GetById(Guid clientId) { return(Execute(context => { var provider = context.Providers.SingleOrDefault(p => p.ProviderId == clientId); if (provider != null) { return new Models.Client(provider.ProviderId, provider.LastUpdateTimestamp.Ticks) { Name = provider.Name, Type = "Provider" } } ; Data.ListItem funder = context.ListItems.Single(li => li.ListItemId == clientId); return new Models.Client(funder.ListItemId, funder.LastUpdateTimestamp.Ticks) { Name = funder.Name, Type = "Funder" }; })); }
public List <Models.ListItem> GetList(string listName, string orderBy = "Name", System.Linq.Expressions.Expression <Func <Data.ListItem, bool> > filter = null, int limit = -1, bool deep = true) { Guid parentId = Execute(cx => { Data.ListItem parent = null; foreach (string parentName in listName.Split(',', ' ', '/', '\\')) { if (parent == null) { parent = cx.ListItems.Single(li => li.Parent == parent && li.Name == parentName); } else { parent = parent.Children.Single(li => li.Name == parentName); } } return(parent.ListItemId); }); return(GetListByParentId(parentId, orderBy, filter, limit, deep)); }
public UpdateResult AddNewUsers(List <Models.Account> newUsers, string clientId, List <string> permissions, string lastUpdateUsername) { try { return(Execute(context => { Guid lastUpdateAccountId = context.Accounts.Single(a => a.Username == lastUpdateUsername).AccountId; Guid cid = BaseModel.DecryptId(clientId); Data.Provider provider = context.Providers.SingleOrDefault(p => p.ProviderId == cid); Data.ListItem funder = context.ListItems.SingleOrDefault(li => li.ListItemId == cid); List <Data.Account> inserts = new List <Data.Account>(); foreach (var user in newUsers) { var newData = new Data.Account { Username = user.Username, FirstName = user.FirstName, LastName = user.LastName, EmailAddress = user.EmailAddress, Password = string.Empty, FirstSignIn = true, ResetBySuperAdmin = false, AccountTypeId = DataAccess.ListItem.GetListItem("AccountType", "User").GUID, StatusId = DataAccess.ListItem.GetListItem("Status", "Active").GUID }; foreach (var permissionId in permissions) { Guid pid = BaseModel.DecryptId(permissionId); if (provider != null) { newData.ProviderAccountPermissions.Add(new ProviderAccountPermission { ProviderId = cid, PermissionId = pid }); } else if (funder != null) { newData.FunderAccountPermissions.Add(new FunderAccountPermission { FunderId = cid, PermissionId = pid }); } } context.Accounts.Add(newData); inserts.Add(newData); } WriteAudit(context, lastUpdateAccountId); inserts.ForEach(a => { a.LastUpdateAccountId = lastUpdateAccountId; a.LastUpdateTimestamp = DateTime.Now; a.DateCreatedTimestamp = DateTime.Now; }); context.SaveChanges(); return new UpdateResult(true); })); } catch (Exception ex) { return(new UpdateResult("Error inserting new users")); } }
public ScoreValue(Data.ListItem data) : base(data.ListItemId, data.LastUpdateTimestamp.Ticks) { ScoreValueId = data.ListItemId; Value = data.Value; }