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 async Task PutGroup(ShoutGroupDto group) { try { using (var client = NewHttpClient()) { var response = await PutAsJsonAsync(client, "api/shoutgroups/" + group.ID, group); response.EnsureSuccessStatusCode(); } } catch (Exception e) { return; } }
public async Task CreateGroupCommand(ShoutGroupDto group) { try { using (var client = NewHttpClient()) { var response = await PostAsJsonAsync(client, "api/shoutgroups", group); response.EnsureSuccessStatusCode(); } } catch (Exception) { return; } }
public override void OnNavigatingTo(NavigationParameters parameters) { m_Shout = (ShoutDto)parameters["model"]; RaisePropertyChanged(nameof(GroupID)); RaisePropertyChanged(nameof(ID)); RaisePropertyChanged(nameof(ShoutTitle)); RaisePropertyChanged(nameof(Cost)); m_ShoutGroup = (ShoutGroupDto)parameters["group"]; RaisePropertyChanged(nameof(TrackCost)); foreach (var u in m_ShoutGroup.Users) { UsersForShout.Add(u); } if (m_Shout.ShoutUserID != Guid.Empty) { SelectedIndex = UsersForShout.IndexOf(UsersForShout.FirstOrDefault(x => x.ID == m_Shout.ShoutUserID)); } RaisePropertyChanged("UserName"); }
public override void OnNavigatingTo(NavigationParameters parameters) { ShoutGroup = (ShoutGroupDto)parameters["group"]; }
public IHttpActionResult PostShoutGroup(ShoutGroupDto shoutGroupDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ShoutGroup shoutGro = new ShoutGroup() { ID = shoutGroupDto.ID, Name = shoutGroupDto.Name, TrackCost = shoutGroupDto.TrackCost, Category = shoutGroupDto.Category, Shouts = new List <Shout>(), ShoutUsers = new List <ShoutUser>() }; var shoutUsersForGroup = new List <ShoutUser>(); foreach (var shoutGroupUser in shoutGroupDto.Users) { ShoutUser foundUser = null; if (shoutGroupUser.ID != null && shoutGroupUser.ID != Guid.Empty) { foundUser = db.ShoutUsers.FirstOrDefault(x => x.ID == shoutGroupUser.ID); } else if (foundUser == null && !String.IsNullOrEmpty(shoutGroupUser.Email)) { foundUser = db.ShoutUsers.FirstOrDefault(x => x.Email.Equals(shoutGroupUser.Email, StringComparison.OrdinalIgnoreCase)); } if (foundUser != null) { shoutGro.ShoutUsers.Add(foundUser); if (foundUser.ShoutGroups == null) { foundUser.ShoutGroups = new List <ShoutGroup>(); } foundUser.ShoutGroups.Add(shoutGro); shoutUsersForGroup.Add(foundUser); } else { var newUser = new ShoutUser() { ID = Guid.NewGuid(), Email = shoutGroupUser.Email, UserName = shoutGroupUser.UserName }; if (newUser.ShoutGroups == null) { newUser.ShoutGroups = new List <ShoutGroup>(); } newUser.ShoutGroups.Add(shoutGro); shoutGro.ShoutUsers.Add(newUser); db.ShoutUsers.Add(newUser); } } foreach (var sh in shoutUsersForGroup) { db.ShoutUsers.Attach(sh); } ShoutGroupIcon shoutGroupIcon = new ShoutGroupIcon() { ShoutGroupID = shoutGro.ID, ShoutGroup = shoutGro, ShoutIconIndex = shoutGroupDto.ShoutGroupIconIndex }; shoutGro.GroupIcon = shoutGroupIcon; db.ShoutGroups.Add(shoutGro); try { db.SaveChanges(); } catch (DbUpdateException) { if (ShoutGroupExists(shoutGroupDto.ID)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = shoutGroupDto.ID }, shoutGroupDto)); }
public IHttpActionResult PutShoutGroup(Guid id, ShoutGroupDto shoutGroupDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != shoutGroupDto.ID) { return(BadRequest()); } ShoutGroup shoutGroup = db.ShoutGroups.Include(sgi => sgi.GroupIcon).FirstOrDefault(x => x.ID == id); db.ShoutGroups.Attach(shoutGroup); shoutGroup.Name = shoutGroupDto.Name; shoutGroup.TrackCost = shoutGroupDto.TrackCost; shoutGroup.Category = shoutGroupDto.Category; if (shoutGroup.GroupIcon == null) { ShoutGroupIcon sgi = new ShoutGroupIcon() { ShoutGroup = shoutGroup, ShoutIconIndex = shoutGroupDto.ShoutGroupIconIndex, }; shoutGroup.GroupIcon = sgi; } else { shoutGroup.GroupIcon.ShoutIconIndex = shoutGroupDto.ShoutGroupIconIndex; } //var shoutUsersForGroup = new List<ShoutUser>(); //foreach (var shoutGroupUser in shoutGroupDto.Users) //{ // ShoutUser foundUser = null; // if (shoutGroupUser.ID != null && shoutGroupUser.ID != Guid.Empty) // { // foundUser = db.ShoutUsers.FirstOrDefault(x => x.ID == shoutGroupUser.ID); // } // else if (foundUser == null && !String.IsNullOrEmpty(shoutGroupUser.Email)) // { // foundUser = db.ShoutUsers.FirstOrDefault(x => x.Email.Equals(shoutGroupUser.Email, StringComparison.OrdinalIgnoreCase)); // } // if (foundUser != null) // { // shoutGroup.ShoutUsers.Add(foundUser); // if (foundUser.ShoutGroups == null) // { // foundUser.ShoutGroups = new List<ShoutGroup>(); // } // //foundUser.ShoutGroups.Add(shoutGroup); // //foundUser.ShoutGroups.FirstOrDefault(x => x.ID ==) // shoutUsersForGroup.Add(foundUser); // } // else // { // var newUser = new ShoutUser() { ID = Guid.NewGuid(), Email = shoutGroupUser.Email, UserName = shoutGroupUser.UserName }; // if (newUser.ShoutGroups == null) // { // newUser.ShoutGroups = new List<ShoutGroup>(); // } // newUser.ShoutGroups.Add(shoutGroup); // shoutGroup.ShoutUsers.Add(newUser); // db.ShoutUsers.Add(newUser); // } //} //foreach (var sh in shoutUsersForGroup) //{ // db.ShoutUsers.Attach(sh); //} db.Entry(shoutGroup).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ShoutGroupExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }