Beispiel #1
0
        public bool Create(string name)
        {
            bool created = false;

            using (var model = new ShcDataModel())
            {
                var squads = model.Squads;
                var squad  = squads.SingleOrDefault(x => x.Name == name);
                if (squad == null)
                {
                    squad = new Squad {
                        Name = name, Description = ""
                    };
                    squads.Add(squad);
                    model.SaveChanges();

                    created = true;

                    squad = squads.SingleOrDefault(x => x.Name == name);
                    Squad = squad;
                    var admins = model.SquadAdmins;
                    admins.Add(new SquadAdmin {
                        Squad = squad.Id, Adminhash = Adminhash, Id = 0
                    });
                    model.SaveChanges();
                }
            }
            return(created);
        }
Beispiel #2
0
        public void AddItem(int itemId)
        {
            using (var model = new ShcDataModel())
            {
                model.SquadItems.Add(new SquadItem {
                    Item = itemId, Squad = Squad.Id
                });
                model.SaveChanges();

                var userItems = model.UserItems;
                var item      = model.SquadItems.Single(x => x.Item == itemId && x.Squad == Squad.Id);
                var items     = userItems.Where(x => x.Squad == Squad.Id)
                                .Select(u => u.Userhash)
                                .Distinct().ToList();

                if (!items.Contains(Userhash))
                {
                    items.Add(Userhash);
                }

                foreach (var i in items)
                {
                    var userItem = new UserItem {
                        Item = itemId, Squad = Squad.Id, Userhash = i, Value = ItemValue.None
                    };
                    userItems.Add(userItem);
                }
                model.SaveChanges();
            }
        }
        public void Join(int id)
        {
            using (var model = new ShcDataModel())
            {
                var memberShip = model.SquadMembers.SingleOrDefault(v => v.Squad == id && v.Userhash == Userhash);

                if (memberShip == null)
                {
                    memberShip = new SquadMember()
                    {
                        Squad = id, Userhash = Userhash
                    };
                    model.SquadMembers.Add(memberShip);

                    model.SaveChanges();
                }

                var squadItems = model.SquadItems.Where(sqi => sqi.Squad == id).Select(x => x.Item);
                var useritems  = model.UserItems.Where(ui => ui.Userhash == Userhash && ui.Squad == id).Select(x => x.Item);
                var join       = squadItems.Except(useritems);
                foreach (var item in join)
                {
                    model.UserItems.Add(new UserItem {
                        Userhash = Userhash, Item = item, Squad = id, Value = ItemValue.None
                    });
                }

                model.SaveChanges();
            }
        }
        public ItemData SetUserValue(int itemid, ItemValue value, int squadid)
        {
            ItemData itemData = null;

            using (var model = new ShcDataModel())
            {
                var item = model.UserItems.SingleOrDefault(x => x.Userhash == Userhash && x.Item == itemid && x.Squad == squadid);
                if (item == null)
                {
                    item = new UserItem {
                        Userhash = Userhash, Item = itemid, Squad = squadid, Value = value
                    };
                    model.UserItems.Add(item);
                }
                else
                {
                    item.Value = value;
                }
                model.SaveChanges();
                var titem = model.Items.FirstOrDefault(x => x.Id == itemid);
                itemData = new ItemData(titem, value, model.UserItems.Where(x => x.Squad == squadid && x.Item == itemid && x.Value > ItemValue.None));

                return(itemData);
            }
        }
 public void Leave(int id)
 {
     using (var model = new ShcDataModel())
     {
         model.UserItems.RemoveRange(model.UserItems.Where(x => x.Squad == id));
         model.SquadMembers.RemoveRange(model.SquadMembers.Where(x => x.Squad == id && x.Userhash == Userhash));
         model.SaveChanges();
     }
 }
Beispiel #6
0
 public void DeleteSquad()
 {
     using (var model = new ShcDataModel())
     {
         model.UserItems.RemoveRange(model.UserItems.Where(x => x.Squad == Squad.Id));
         model.SquadAdmins.RemoveRange(model.SquadAdmins.Where(x => x.Squad == Squad.Id));
         model.Squads.RemoveRange(model.Squads.Where(x => x.Id == Squad.Id));
         model.SquadMembers.RemoveRange(model.SquadMembers.Where(x => x.Id == Squad.Id));
         model.SquadItems.RemoveRange(model.SquadItems.Where(x => x.Id == Squad.Id));
         model.SaveChanges();
     }
 }
Beispiel #7
0
        public void RemoveItem(int itemId)
        {
            using (var model = new ShcDataModel())
            {
                var t    = model.SquadItems;
                var item = t.Where(x => x.Squad == Squad.Id && x.Item == itemId);
                if (!item.Any())
                {
                    return;
                }

                var userItems = model.UserItems;
                userItems.RemoveRange(userItems.Where(x => x.Squad == Squad.Id && x.Item == itemId));

                t.RemoveRange(item);
                model.SaveChanges();
            }
        }