コード例 #1
0
        private bool SaveOrUpdateGroup(bool redirectHome)
        {
            var isExisting = currentGroup != null;
            var group      = currentGroup ?? new ShoutGroup();

            group.Name      = GroupName.Text;
            group.GroupIcon = GetEnabledButton();

            if (isExisting)
            {
                if (group.UpdateGroup() && redirectHome)
                {
                    appSettings.CurrentGroup = group;
                    NavigationService.Navigate(new Uri("/Pages/MainPage.xaml", UriKind.Relative));
                }
            }
            else
            {
                if (group.AddGroup() && redirectHome)
                {
                    appSettings.CurrentGroup = group;
                    NavigationService.Navigate(new Uri("/Pages/MainPage.xaml", UriKind.Relative));
                }
            }

            currentGroup = group;
            return(true);
        }
コード例 #2
0
        public IHttpActionResult DeleteShoutGroup(Guid id)
        {
            ShoutGroup shoutGroup = db.ShoutGroups.Find(id);

            if (shoutGroup == null)
            {
                return(NotFound());
            }

            db.ShoutGroups.Remove(shoutGroup);
            db.SaveChanges();

            return(Ok(shoutGroup));
        }
コード例 #3
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // Get a dictionary of query string keys and values.
            IDictionary <string, string> queryStrings = this.NavigationContext.QueryString;

            // Ensure that there is at least one key in the query string, and check whether the "token" key is present.
            if (queryStrings.ContainsKey("groupId"))
            {
                currentGroup = appSettings.AvailableGroups.SingleOrDefault(g => g.GroupId == queryStrings["groupId"]);
                PopulateForm();
            }
            else
            {
                this.GroupMembers.ItemsSource = new List <Shouter> {
                    new Shouter {
                        Name = ShoutGroupExtensions.DefaultShoutName, TimesShouted = 0
                    }
                };
            }
        }
コード例 #4
0
        protected override void Seed(WhoseShoutWebService.Models.ApplicationDbContext context)
        {
            var shout = new Shout
            {
                ID              = new Guid("45def82e-2b68-47e1-98c6-7d34906b46f1"),
                ShoutGroupID    = new Guid("bf3641d1-a384-494d-a957-18f2aa42170c"),
                ShoutUserID     = new Guid("d9c91004-3994-4bb4-a703-267904985126"),
                Cost            = 9.0f,
                PurchaseTimeUtc = DateTime.UtcNow
            };

            var user1 = new ShoutUser
            {
                ID          = new Guid("d9c91004-3994-4bb4-a703-267904985126"),
                UserName    = "******",
                Email       = "*****@*****.**",
                FacebookID  = "11111111111111111",
                ShoutGroups = new List <ShoutGroup>(),
                Shouts      = new List <Shout>()
            };
            var user2 = new ShoutUser
            {
                ID          = new Guid("c9c9f88b-853b-46e5-a70a-fad212fab6b0"),
                UserName    = "******",
                Email       = "*****@*****.**",
                TwitterID   = "12519262411111111111",
                ShoutGroups = new List <ShoutGroup>(),
                Shouts      = new List <Shout>()
            };
            var user3 = new ShoutUser
            {
                ID          = new Guid("840a9916-ca86-4575-9025-6adb2abfa389"),
                UserName    = "******",
                Email       = "*****@*****.**",
                FacebookID  = "11111111111111112",
                ShoutGroups = new List <ShoutGroup>(),
                Shouts      = new List <Shout>()
            };

            var shoutGroup = new ShoutGroup
            {
                ID         = new Guid("bf3641d1-a384-494d-a957-18f2aa42170c"),
                Category   = "Coffee",
                Name       = "CoffeeTime",
                ShoutUsers = new List <ShoutUser>(),
                Shouts     = new List <Shout>()
            };

            var shoutGroup2 = new ShoutGroup
            {
                ID         = new Guid("9befd37c-62c6-4fcf-9d77-8945c7964e7b"),
                Category   = "Beer",
                Name       = "Beeeeers",
                ShoutUsers = new List <ShoutUser>(),
                Shouts     = new List <Shout>()
            };

            ShoutGroupIcon icon = new ShoutGroupIcon()
            {
                ShoutGroupID   = shoutGroup2.ID,
                ShoutIconIndex = 0,
                ShoutGroup     = shoutGroup2
            };

            shout.ShoutUser  = user1;
            shout.ShoutGroup = shoutGroup;

            user1.ShoutGroups.Add(shoutGroup);
            user2.ShoutGroups.Add(shoutGroup);

            user1.Shouts.Add(shout);

            shoutGroup.ShoutUsers.Add(user1);
            shoutGroup.ShoutUsers.Add(user2);
            shoutGroup.Shouts.Add(shout);

            shoutGroup2.ShoutUsers.Add(user3);

            context.Shouts.AddOrUpdate(p => p.ID, shout);
            context.ShoutUsers.AddOrUpdate(p => p.ID, user1, user2, user3);
            context.ShoutGroups.AddOrUpdate(p => p.ID, shoutGroup, shoutGroup2);
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        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));
        }