public GroupIcon GetGroupWithName(string groupName) { GroupIcon n_Group = null; for (int i = 0; i < m_GroupIcons.Length; i++) { if (m_GroupIcons[i].group.GroupName == groupName) { n_Group = m_GroupIcons[i]; } } return(n_Group); }
public unsafe static bool UpdateIcon(string targetFile, Icon hIcon, int size) { var hRes = BeginUpdateResource(targetFile, false); var currentCulture = CultureInfo.CurrentCulture; var pid = ((ushort)currentCulture.LCID) & 0x3ff; var sid = ((ushort)currentCulture.LCID) >> 10; var languageID = (ushort)((((ushort)pid) << 10) | ((ushort)sid)); if (hRes == IntPtr.Zero) { return(false); } var gc = GCHandle.Alloc(GetIconData(hIcon), GCHandleType.Pinned); if (!UpdateResource(hRes, (IntPtr)3, "0", languageID, (IntPtr)(gc.AddrOfPinnedObject().ToInt32() + 22), (uint)size - 22)) { EndUpdateResource(hRes, true); return(false); } var grpIcon = new GroupIcon { Reserved1 = 0, ResourceType = 1, ImageCount = 1, Width = 32, Height = 32, Colors = 0, Reserved2 = 0, Planes = 2, BitsPerPixel = 32, ImageSize = size - 22, ResourceID = 1 }; if (!UpdateResource(hRes, (IntPtr)14, "MAINICON", languageID, (IntPtr)(&grpIcon), (uint)Marshal.SizeOf(grpIcon))) { EndUpdateResource(hRes, true); return(false); } EndUpdateResource(hRes, false); return(true); }
public static unsafe bool UpdateIcon(string targetFile, Icon hIcon, int size) { var hRes = BeginUpdateResource(targetFile, false); var currentCulture = CultureInfo.CurrentCulture; var pid = ((ushort) currentCulture.LCID) & 0x3ff; var sid = ((ushort) currentCulture.LCID) >> 10; var languageID = (ushort) ((((ushort) pid) << 10) | ((ushort) sid)); if (hRes == IntPtr.Zero) return false; var gc = GCHandle.Alloc(GetIconData(hIcon), GCHandleType.Pinned); if (!UpdateResource(hRes, (IntPtr) 3, "0", languageID, (IntPtr)(gc.AddrOfPinnedObject().ToInt32() + 22), (uint) size -22)) { EndUpdateResource(hRes, true); return false; } var grpIcon = new GroupIcon { Reserved1 = 0, ResourceType = 1, ImageCount = 1, Width = 32, Height = 32, Colors = 0, Reserved2 = 0, Planes = 2, BitsPerPixel = 32, ImageSize = size - 22, ResourceID = 1 }; if (!UpdateResource(hRes, (IntPtr) 14, "MAINICON", languageID, (IntPtr)( &grpIcon ), (uint)Marshal.SizeOf(grpIcon))) { EndUpdateResource(hRes, true); return false; } EndUpdateResource(hRes, false); return true; }
public IHttpActionResult PostGroup(GroupDto groupDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Group gro = new Group() { ID = groupDto.ID, Name = groupDto.Name, TrackCost = groupDto.TrackCost, Category = groupDto.Category, Records = new List <Record>(), Users = new List <User>() }; var usersForGroup = new List <User>(); foreach (var groupUser in groupDto.Users) { User foundUser = null; if (groupUser.ID != null && groupUser.ID != Guid.Empty) { foundUser = db.NXTUsers.FirstOrDefault(x => x.ID == groupUser.ID); } else if (foundUser == null && !String.IsNullOrEmpty(groupUser.Email)) { foundUser = db.NXTUsers.FirstOrDefault(x => x.Email.Equals(groupUser.Email, StringComparison.OrdinalIgnoreCase)); } if (foundUser != null) { gro.Users.Add(foundUser); if (foundUser.Groups == null) { foundUser.Groups = new List <Group>(); } foundUser.Groups.Add(gro); usersForGroup.Add(foundUser); } else { var newUser = new User() { ID = Guid.NewGuid(), Email = groupUser.Email, UserName = groupUser.UserName, Colour = groupUser.Colour }; if (newUser.Groups == null) { newUser.Groups = new List <Group>(); } newUser.Groups.Add(gro); gro.Users.Add(newUser); db.NXTUsers.Add(newUser); } } foreach (var sh in usersForGroup) { db.NXTUsers.Attach(sh); } GroupIcon groupIcon = new GroupIcon() { GroupID = gro.ID, Group = gro, IconName = groupDto.GroupIconName }; gro.GroupIcon = groupIcon; db.Groups.Add(gro); try { db.SaveChanges(); } catch (DbUpdateException) { if (GroupExists(groupDto.ID)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = groupDto.ID }, groupDto)); }
public IHttpActionResult PutGroup(Guid id, GroupDto groupDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != groupDto.ID) { return(BadRequest()); } Group group = db.Groups.Include(sgi => sgi.GroupIcon).FirstOrDefault(x => x.ID == id); db.Groups.Attach(group); group.Name = groupDto.Name; group.TrackCost = groupDto.TrackCost; group.Category = groupDto.Category; if (group.GroupIcon == null) { GroupIcon sgi = new GroupIcon() { Group = group, IconName = groupDto.GroupIconName }; group.GroupIcon = sgi; } else { group.GroupIcon.IconName = groupDto.GroupIconName; } //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(group).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!GroupExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
protected override void Seed(NXTWebService.Models.ApplicationDbContext context) { var record = new Record { ID = new Guid("45def82e-2b68-47e1-98c6-7d34906b46f1"), GroupID = new Guid("bf3641d1-a384-494d-a957-18f2aa42170c"), UserID = new Guid("d9c91004-3994-4bb4-a703-267904985126"), Cost = 9.0f, PurchaseTimeUtc = DateTime.UtcNow }; var user1 = new User { ID = new Guid("d9c91004-3994-4bb4-a703-267904985126"), UserName = "******", Email = "*****@*****.**", FacebookID = "11111111111111111", AvatarUrl = "http://localhost.com", Groups = new List <Group>(), Records = new List <Record>() }; var user2 = new User { ID = new Guid("c9c9f88b-853b-46e5-a70a-fad212fab6b0"), UserName = "******", Email = "*****@*****.**", TwitterID = "12519262411111111111", AvatarUrl = "http://localhost.com", Groups = new List <Group>(), Records = new List <Record>() }; var user3 = new User { ID = new Guid("840a9916-ca86-4575-9025-6adb2abfa389"), UserName = "******", Email = "*****@*****.**", FacebookID = "11111111111111112", GoogleID = "235235235235", AvatarUrl = "http://localhost.com", Groups = new List <Group>(), Records = new List <Record>() }; var group = new Group { ID = new Guid("bf3641d1-a384-494d-a957-18f2aa42170c"), Category = "Coffee", Name = "CoffeeTime", TrackCost = true, Users = new List <User>(), Records = new List <Record>() }; var group2 = new Group { ID = new Guid("9befd37c-62c6-4fcf-9d77-8945c7964e7b"), Category = "Beer", Name = "Beeeeers", TrackCost = false, Users = new List <User>(), Records = new List <Record>() }; GroupIcon icon = new GroupIcon() { GroupID = group2.ID, Group = group2 }; record.User = user1; record.Group = group; user1.Groups.Add(group); user2.Groups.Add(group); user1.Records.Add(record); group.Users.Add(user1); group.Users.Add(user2); group.Records.Add(record); group2.Users.Add(user3); context.Records.AddOrUpdate(p => p.ID, record); context.NXTUsers.AddOrUpdate(p => p.ID, user1, user2, user3); context.Groups.AddOrUpdate(p => p.ID, group, group2); }