public Task AddUserToGroup(string groupId, string userId) { if (Users.Count == 0) { throw new ArgumentException($"no users were preconfigured. Call 'PreConfigureUserInMock' to do so."); } if (!Users.Any(u => u.Id.Equals(userId))) { throw new ArgumentException($"user with id {userId} was not preconfigured. Call 'PreConfigureUserInMock' to do so."); } var user = Users.First(u => u.Id.Equals(userId)); if (!UsersInGroup.ContainsKey(groupId)) { UsersInGroup.Add(groupId, new List <string>() { userId }); } else { var group = UsersInGroup.First(g => g.Key.Equals(groupId)); if (!group.Value.Any(id => id.Equals(userId))) { ; } { group.Value.Add(userId); } } return(Task.CompletedTask); }
public Task <List <UserInfo> > GetAllUsersInGroup(string group) { if (Groups.Count == 0) { throw new ArgumentException($"group {group} was not preconfigured. Call 'PreConfigureGroupInMock' to do so."); } var groupId = Groups.First(g => g.Name.Equals(group, StringComparison.InvariantCultureIgnoreCase)).Id; if (UsersInGroup.Count == 0) { throw new ArgumentException($"no users were preconfigured to be in any group. Call 'PreConfigureGroupOfUser' to do so."); } var groupUserId = UsersInGroup.First(g => g.Key.Equals(groupId)); var allUsersInGroup = new List <UserInfo>(); foreach (var user in groupUserId.Value) { var storedUser = Users.First(u => u.Id.Equals(user)); var groups = GetGroupsForUser(user).ConfigureAwait(false).GetAwaiter().GetResult(); allUsersInGroup.Add(new UserInfo { Id = storedUser.Id, DisplayName = storedUser.DisplayName, FirsName = storedUser.FirsName, LastSignedIn = storedUser.LastSignedIn, LastName = storedUser.LastName, Username = storedUser.Username, Groups = groups }); } return(Task.FromResult(allUsersInGroup)); }
public async void OnUserClickedCommand(int?index) { if (!IsEdit && index.HasValue) { if (index == 0) { return; } else if (index == UsersInGroup.Count - 1) { //Push to page NavigationParameters nav = new NavigationParameters(); nav.Add("friends", Friends); await _navigationService.NavigateAsync("AddUserToGroupPage", nav); } else { var newCollection = new ObservableCollection <UserDto>(UsersInGroup); newCollection.RemoveAt(index.Value); //Terrible UsersInGroup.Clear(); foreach (var u in newCollection) { UsersInGroup.Add(u); } } } }
public override void OnNavigatingTo(NavigationParameters parameters) { base.OnNavigatedTo(parameters); if (parameters["user"] != null) { var user = (UserDto)parameters["user"]; if (user != null) { if (!IsUserInGroup(user)) { var newCollection = new ObservableCollection <UserDto>(UsersInGroup); newCollection.Insert(UsersInGroup.Count - 1, user); //Terrible UsersInGroup.Clear(); foreach (var u in newCollection) { UsersInGroup.Add(u); } } } } else { if (parameters["group"] != null) { this.Group = (GroupDto)parameters["group"]; RaisePropertyChanged(nameof(Group)); GroupName = Group.Name; TrackCost = Group.TrackCost; SelectedIconName = Group.GroupIconName; RaisePropertyChanged(nameof(GroupName)); //UsersInGroup = new ObservableCollection<ShoutUserDto>(Group.Users); UsersInGroup.Clear(); UsersInGroup = new ObservableCollection <UserDto>(Group.Users); RaisePropertyChanged(nameof(UsersInGroup)); } else { UsersInGroup.Add(Settings.Current.User); UserDto u = new UserDto(); u.ID = DummyGuid; u.AvatarUrl = "ic_plus_white_18dp.png"; UsersInGroup.Add(u); } if (parameters["shout"] != null) { ShoutFromEdit = (RecordDto)parameters["shout"]; } if (parameters["edit"] != null) { IsEdit = true; Title = "Edit Group"; RaisePropertyChanged(nameof(IsEdit)); } } }
public void DeleteUsersInGroup(UsersInGroup currentData) { if ((currentData.EntityState == EntityState.Detached)) { this.ObjectContext.UsersInGroup.Attach(currentData); } this.ObjectContext.DeleteObject(currentData); }
public void OnRemoveUserCommand(int?index) { ShowColours = true; if (index.HasValue) { UsersInGroup.RemoveAt(index.Value); } }
private bool CreateCommandCanExecute() { if (UsersInGroup.FirstOrDefault(x => x.ID != DummyGuid && x.ID != Settings.Current.UserGuid) != null && !String.IsNullOrEmpty(GroupName)) { return(true); } return(false); }
private bool IsUserInGroup(UserDto user) { if (UsersInGroup.Contains(user)) { return(true); } return(false); }
public int CreateUserInGroup(Group group, string userId) { UsersInGroup userInGroup = new UsersInGroup() { Group = group, UserId = userId, }; _repository.Add(userInGroup); return(group.Id); }
public async void OnCreateGroupCommand() { if (IsEdit) { if (CurrentApp.Current.MainViewModel.GroupColourDictionary.ContainsKey(Group.ID)) { CurrentApp.Current.MainViewModel.GroupColourDictionary[Group.ID] = SelectedColour; } else { CurrentApp.Current.MainViewModel.GroupColourDictionary.Add(Group.ID, SelectedColour); } await CurrentApp.Current.MainViewModel.SaveGroupColours(); Group.Name = ShoutName; Group.Users = UsersInGroup.ToList(); Group.TrackCost = TrackCost; Group.ShoutGroupIconIndex = SelectedIconIndex; await CurrentApp.Current.MainViewModel.ServiceApi.PutGroup(Group); OnGoBack(); } else { Group = new ShoutGroupDto() { ID = Guid.NewGuid(), Name = ShoutName, TrackCost = TrackCost, Users = UsersInGroup.ToList() }; Group.Users.Add(new ShoutUserDto() { ID = Settings.Current.UserGuid }); await CurrentApp.Current.MainViewModel.ServiceApi.CreateGroupCommand(Group); NavigationParameters nav = new NavigationParameters(); CurrentApp.Current.MainViewModel.GroupColourDictionary.Add(Group.ID, SelectedColour); await CurrentApp.Current.MainViewModel.SaveGroupColours(); var groups = await CurrentApp.Current.MainViewModel.ServiceApi.GetShoutGroups(Settings.Current.UserGuid.ToString()); nav.Add("model", groups); await _navigationService.NavigateAsync("/NavigationPage/SummaryPage", nav); } await CurrentApp.Current.MainViewModel.SaveGroupColours(); }
public void UpdateUsersInGroup(UsersInGroup currentData) { UsersInGroup user = this.ChangeSet.GetOriginal(currentData); if (user != null) { this.ObjectContext.CreateObjectSet<UsersInGroup>().AttachAsModified(currentData, user); } else { this.ObjectContext.UsersInGroup.Attach(currentData); } this.ObjectContext.SaveChanges(); }
public Task RemoveUserFromGroup(string groupId, string userId) { var user = Users.First(u => u.Id.Equals(userId)); if (UsersInGroup.ContainsKey(groupId)) { if (UsersInGroup[groupId].Exists(u => u.Equals(userId))) { UsersInGroup[groupId].Remove(user.Id); return(Task.CompletedTask); } throw new ArgumentException("user does not exists"); } throw new ArgumentException("group does not exists"); }
public void InsertUsersInGroup(UsersInGroup group) { if ((group.EntityState != EntityState.Added)) { if ((group.EntityState != EntityState.Detached)) { this.ObjectContext.ObjectStateManager. ChangeObjectState(group, EntityState.Added); } else { this.ObjectContext.AddToUsersInGroup(group); } } }
public async void OnCreateGroupCommand() { var dummy = UsersInGroup.FirstOrDefault(x => x.ID == DummyGuid); UsersInGroup.Remove(dummy); if (IsEdit) { Group.Name = GroupName; Group.Users = UsersInGroup.ToList(); Group.TrackCost = TrackCost; Group.GroupIconName = SelectedIconName; await CurrentApp.MainViewModel.ServiceApi.PutGroup(Group); OnGoBack(true); } else { Group = new GroupDto() { ID = Guid.NewGuid(), Name = GroupName, TrackCost = TrackCost, GroupIconName = SelectedIconName, Users = UsersInGroup.ToList() }; await CurrentApp.MainViewModel.ServiceApi.CreateGroupCommand(Group); NavigationParameters nav = new NavigationParameters(); if (CurrentApp.MainViewModel.GroupColourDictionary == null) { CurrentApp.MainViewModel.GroupColourDictionary = new Dictionary <Guid, string>(); } var groups = await CurrentApp.MainViewModel.ServiceApi.GetGroups(Settings.Current.UserGuid.ToString()); nav.Add("model", groups); nav.Add("alert", "Group created!"); await _navigationService.NavigateAsync("/NavigationPage/SummaryPage?refresh=1", nav); } }
public override void OnNavigatingTo(NavigationParameters parameters) { if (parameters["group"] != null) { this.Group = (ShoutGroupDto)parameters["group"]; RaisePropertyChanged(nameof(Group)); ShoutName = Group.Name; TrackCost = Group.TrackCost; RaisePropertyChanged(nameof(ShoutName)); //UsersInGroup = new ObservableCollection<ShoutUserDto>(Group.Users); UsersInGroup.Clear(); UsersInGroup = new ObservableCollection <ShoutUserDto>(Group.Users); RaisePropertyChanged(nameof(UsersInGroup)); //foreach (var u in Group.Users) //{ // UsersInGroup.Add(u); //} if (CurrentApp.Current.MainViewModel.GroupColourDictionary.ContainsKey(Group.ID)) { SelectedColour = CurrentApp.Current.MainViewModel.GroupColourDictionary[Group.ID]; } } else { Random r = new Random(); SelectedColour = MyColours[r.Next(19)]; } if (parameters["shout"] != null) { ShoutFromEdit = (ShoutDto)parameters["shout"]; } if (parameters["edit"] != null) { IsEdit = true; } }
public ShoutGroupPageViewModel(INavigationService navigationService, IEventAggregator eventAggregator) : base(navigationService) { Button b = new Button(); var x2 = (FileImageSource)ImageSource.FromFile("ic_coffee_outline_white_48dp.png"); var x1 = (FileImageSource)ImageSource.FromFile("ic_food_croissant_white_48dp.png"); Icons.Add(x1); Icons.Add(x2); m_NavigationService = navigationService; m_EventAggregator = eventAggregator; CreateGroupCommand = new DelegateCommand(OnCreateGroupCommand); AddUserToGroupCommand = new DelegateCommand(OnAddUserToGroupCommand); CancelCommand = new DelegateCommand(OnCancelCommand); ClickColourCommand = new Command <object>(OnClickColourCommand); ClickColour = new DelegateCommand(OnClickColour); ClickIconCommand = new Command <object>(OnClickIconCommand); ClickIcon = new DelegateCommand(OnClickIcon); RemoveUserCommand = new DelegateCommand <int?>(OnRemoveUserCommand); UsersInGroup.Add(new ShoutUserDto()); Colours = MyColours; }
public void Delete(UsersInGroup userInGroup) { _repository.Delete(userInGroup); }
public void OnAddUserToGroupCommand() { UsersInGroup.Add(new ShoutUserDto()); RaisePropertyChanged(nameof(UsersInGroup)); }
public async Task <IActionResult> CreateProject([FromBody] ProjectCreationData data) { var db = Database; var currentDate = DateTime.UtcNow; var currentUser = await(from u in db.Query <User>() where u.Key == HttpContext.User.Identity.Name select u).FirstOrDefaultAsync(); if (currentUser == null) { return(Unauthorized()); } var groupGraph = db.Graph("GroupUsersGraph"); // obtenemos los usuarios var usersToAdd = from u in db.Query <User>() from ud in data.Members where u.Username == ud select u; if (data.Members.Count != usersToAdd.Count()) { return(BadRequest(new { message = "Some users are invalid" })); } // En caso de que el usuario haya puesto su nombre de usuario, lo eliminamos, el se añade aparte puesto que será administrador usersToAdd = from u in usersToAdd where u.Key != currentUser.Key select u; var projectGroup = new Group { CreationDate = currentDate, Name = data.Name, GroupOwner = HttpContext.User.Identity.Name, IsRoot = true, Description = $"# {data.Name}\nEsta descripción es generada automaticamente, si eres el administrador puedes cambiarla en el panel de administrador", KanbanBoards = new List <KanbanBoard> { new KanbanBoard(data.Name) }, Events = new List <CalendarEvent>(), PreviousProject = data.PreviousProject }; // Default kanban creation projectGroup.KanbanBoards[0].Members = await usersToAdd.Select(u => new Models.Kanban.KanbanGroupMember { UserId = u.Key }).ToListAsync(); projectGroup.KanbanBoards[0].Members.Add(new Models.Kanban.KanbanGroupMember { UserId = currentUser.Key, MemberPermissions = Models.Kanban.KanbanMemberPermissions.Admin }); var createdGroup = await db.InsertAsync <Group>(projectGroup); var admin = new UsersInGroup { IsAdmin = true, JoinDate = currentDate, Group = createdGroup.Id, User = "******" + currentUser.Key, AddedBy = currentUser.Key }; // create a relation between root group and the creator await groupGraph.InsertEdgeAsync <UsersInGroup>(admin); foreach (var user in usersToAdd) { var userToAdd = new UsersInGroup { IsAdmin = false, JoinDate = currentDate, Group = createdGroup.Id, User = "******" + user.Key, AddedBy = currentUser.Key }; await groupGraph.InsertEdgeAsync <UsersInGroup>(userToAdd); var notificationMessage = string.Format($"{currentUser.Username} te ha agregado " + $"al proyecto '{projectGroup.Name}'", projectGroup.Name); var notification = new Notification { Read = false, Message = notificationMessage, Priority = NotificationPriority.Medium, Context = $"project/{createdGroup.Key}" }; // enviar la notificación await NotificationHub.Clients .Group("Users/" + user.Key) .SendAsync("notificationReceived", notification); user.Notifications.Add(notification); await db.UpdateByIdAsync <User>(user.Id, user); } return(Created("/api/projects/" + createdGroup.Key, null)); }
public string GetId(UsersInGroup userInGroup) { return(_repository.GetId(userInGroup)); }
public int Create(UsersInGroup userInGroup) { _repository.Add(userInGroup); return(userInGroup.Id); }