public static List <UserActionView> GetActionsForViewsForUser(ApplicationDbContext db, IPrincipal user) { List <UserActionView> list = new List <UserActionView>(); List <UserAction> userActionList = UserActionHelpers.GetActionsForUser(db, user); foreach (UserAction userAction in userActionList) { string referenceName = ""; switch (userAction.ActionLevel) { case LevelEnum.Company: referenceName = CompanyHelpers.GetCompanyNameTownPostCode(db, userAction.ReferenceKey); break; case LevelEnum.Branch: referenceName = BranchHelpers.GetBranchNameTownPostCode(db, userAction.ReferenceKey); break; case LevelEnum.User: referenceName = AppUserHelpers.GetAppUserName(db, userAction.ReferenceKey); break; } string createdByName = ""; //Get the user that created the action. Note, this could be at Company or Branch level, so try the user first, if that //fails then work through a switch try { createdByName = AppUserHelpers.GetAppUserName(db, userAction.CreatedBy); } catch { switch (userAction.ActionLevel) { case LevelEnum.Company: createdByName = CompanyHelpers.GetCompanyNameTownPostCode(db, userAction.CreatedBy); break; case LevelEnum.Branch: createdByName = BranchHelpers.GetBranchNameTownPostCode(db, userAction.CreatedBy); break; } } list.Add(CreateUserActionView(userAction, referenceName, createdByName)); } return(list); }
public static GroupMember CreateGroupMember(ApplicationDbContext db, Group group, Guid referenceId, GroupMemberStatusEnum status) { GroupMember member = new GroupMember() { GroupMemberId = Guid.NewGuid(), GroupId = group.GroupId, Type = group.Type, ReferenceId = referenceId, AddedBy = group.GroupOriginatorAppUserId, AddedDateTime = DateTime.Now, Status = status }; db.GroupMembers.Add(member); db.SaveChanges(); //Create ACTION if this is created with a waiting status - actions created dependent on group acceptancelevel UserActionHelpers.CreateActionForGroupMemberAccceptance(db, group, member); return(member); }
public static Friend CreateFriend(ApplicationDbContext db, LevelEnum level, Guid ofReferenceId, Guid byReferenceId, Guid byAppUserId) { Friend friend = new Friend() { FriendId = Guid.NewGuid(), Type = level, RequestedById = byReferenceId, RequestedOfId = ofReferenceId, RequestedByUserId = byAppUserId, Status = FriendStatusEnum.Requested, RequestedOn = DateTime.Now }; db.Friends.Add(friend); db.SaveChanges(); //Now add Action to the user or manager of branch or admin of company to change status UserActionHelpers.CreateActionForFriendRequestFromUser(db, level, ofReferenceId, byReferenceId); //LSLSLS PSPSPS change the searches to only look for those that are active not 'awaiting'......think abou tthat return(friend); }