/// <summary>
        /// Inserts or Updates a Clan War depending on the parameters received.
        /// </summary>
        /// <param name="clanWarViewModel">A ClanWarViewModel object, if its Id is NULL then do an Insert, else Updates.</param>
        public static int Upsert(ClanWarUpsertViewModel clanWarViewModel, int userId)
        {
            Enums.Action action  = Enums.Action.Create;
            ClanWar      clanWar = ClanWarManager.ConvertViewToModel(clanWarViewModel);

            using (var dbContext = new HouseOfClansEntities())
            {
                if (clanWarViewModel.Id == null)
                {
                    clanWar.addedOn = DateTime.Now;
                    dbContext.ClanWars.Add(clanWar);

                    if (dbContext.SaveChanges() > 0)
                    {
                        ActionLogManager.Log <ClanWarUpsertViewModel>(action, userId, null, null, string.Format("Clan War Id: {0}", clanWar.id));
                    }
                }
                else
                {
                    ClanWar original = ClanWarManager.SelectByClanWarId(clanWar.id);
                    action            = Enums.Action.Update;
                    clanWar.updatedOn = DateTime.Now;
                    dbContext.Entry(clanWar).State = EntityState.Modified;

                    if (dbContext.SaveChanges() > 0)
                    {
                        List <ActionLog> changes = GetChanges(clanWar, original);
                        ActionLogManager.Log <ClanWarUpsertViewModel>(action, userId, changes);
                    }
                }
            }

            return(clanWar.id);
        }
Exemple #2
0
 /// <summary>
 /// Inserts a new UserBlackList record
 /// </summary>
 public static void Insert(UserBlackList bUser)
 {
     using (var dbContext = new HouseOfClansEntities())
     {
         bUser.addedOn = DateTime.Now;
         dbContext.UserBlackLists.Add(bUser);
         dbContext.SaveChanges();
     }
 }
 /// <summary>
 /// Inserts a new ClanGroup
 /// </summary>
 public static void Insert(ClanGroup clanGroup)
 {
     using (var dbContext = new HouseOfClansEntities())
     {
         clanGroup.addedOn = DateTime.Now;
         dbContext.ClanGroups.Add(clanGroup);
         dbContext.SaveChanges();
     }
 }
 /// <summary>
 /// Inserts a new Rule
 /// </summary>
 public static void Insert(Rule rule)
 {
     using (var dbContext = new HouseOfClansEntities())
     {
         rule.addedOn = DateTime.Now;
         dbContext.Rules.Add(rule);
         dbContext.SaveChanges();
     }
 }
 /// <summary>
 /// Inserts a new Request record
 /// </summary>
 public static void Insert(Request req)
 {
     using (var dbContext = new HouseOfClansEntities())
     {
         req.addedOn = DateTime.Now;
         dbContext.Requests.Add(req);
         dbContext.SaveChanges();
     }
 }
        /// <summary>
        /// Updates a Request
        /// </summary>
        public static void Update(Request updatedReq)
        {
            Request newReq = RequestManager.SelectById(updatedReq.id);

            using (var dbContext = new HouseOfClansEntities())
            {
                updatedReq.updatedOn = DateTime.Now;
                dbContext.Requests.Attach(newReq);
                dbContext.Entry(newReq).CurrentValues.SetValues(updatedReq);
                dbContext.SaveChanges();
            }
        }
        /// <summary>
        /// Updates a ClanGroup
        /// </summary>
        public static void Update(ClanGroup clanGroup)
        {
            using (var dbContext = new HouseOfClansEntities())
            {
                ClanGroup clanGroupInfo = ClanGroupManager.SelectByClanGroupId(clanGroup.id);
                clanGroupInfo.updatedOn = DateTime.Now;

                dbContext.ClanGroups.Attach(clanGroupInfo);
                dbContext.Entry(clanGroupInfo).CurrentValues.SetValues(clanGroup);
                dbContext.SaveChanges();
            }
        }
        /// <summary>
        /// Updates a Rule
        /// </summary>
        public static void Update(Rule rule)
        {
            using (var dbContext = new HouseOfClansEntities())
            {
                Rule ruleInfo = RuleManager.SelectByRuleId(rule.id);
                ruleInfo.updatedOn = DateTime.Now;

                dbContext.Rules.Attach(ruleInfo);
                dbContext.Entry(ruleInfo).CurrentValues.SetValues(rule);
                dbContext.SaveChanges();
            }
        }
        /// <summary>
        /// Updates the current Clan User
        /// </summary>
        public static void Update(ClanUser updatedClanUser)
        {
            ClanUser clanUser = ClanUserManager.SelectByClanUserId(updatedClanUser.id);

            using (var dbContext = new HouseOfClansEntities())
            {
                updatedClanUser.updatedOn = DateTime.Now;
                dbContext.ClanUsers.Attach(clanUser);
                dbContext.Entry(clanUser).CurrentValues.SetValues(updatedClanUser);
                dbContext.SaveChanges();
            }
        }
Exemple #10
0
        /// <summary>
        /// Updates a UserBlackList
        /// </summary>
        public static void Update(UserBlackList updatedBUser)
        {
            UserBlackList bUser = BlacklistManager.SelectByBlacklistId(updatedBUser.id);

            using (var dbContext = new HouseOfClansEntities())
            {
                //TODO: Add updatedOn for the UserBlackList entity in the database
                //updatedBUser.updatedOn = DateTime.Now;
                dbContext.UserBlackLists.Attach(bUser);
                dbContext.Entry(bUser).CurrentValues.SetValues(updatedBUser);
                dbContext.SaveChanges();
            }
        }
        /// <summary>
        /// Deletes a Request
        /// </summary>
        public static bool Delete(int requestId)
        {
            bool    isDeleted = false;
            Request deleteReq = RequestManager.SelectById(requestId);

            using (var dbContext = new HouseOfClansEntities())
            {
                dbContext.Requests.Attach(deleteReq);
                dbContext.Requests.Remove(deleteReq);
                isDeleted = dbContext.SaveChanges() > 0;
            }

            return(isDeleted);
        }
        /// <summary>
        /// Deletes the Picks of the current Clan War
        /// </summary>
        public static bool Delete(int warId)
        {
            bool isDeleted = false;

            using (var dbContext = new HouseOfClansEntities())
            {
                dbContext.WarRankings.RemoveRange(dbContext.WarRankings.Where(p => p.clanWarId == warId));
                dbContext.SaveChanges();
            }

            isDeleted = !RankingsManager.SelectRankingsByClanWarId(warId).Any();

            return(isDeleted);
        }
        /// <summary>
        /// Deletes the current Clan War
        /// </summary>
        public static bool Delete(int warId)
        {
            bool    isDeleted = false;
            ClanWar deleteWar = ClanWarManager.SelectByClanWarId(warId);

            using (var dbContext = new HouseOfClansEntities())
            {
                dbContext.ClanWars.Attach(deleteWar);
                dbContext.ClanWars.Remove(deleteWar);
                isDeleted = dbContext.SaveChanges() > 0;
            }

            return(isDeleted);
        }
        /// <summary>
        /// Deletes a rule
        /// </summary>
        public static bool Delete(int ruleId)
        {
            bool isDeleted  = false;
            Rule deleteRule = RuleManager.SelectByRuleId(ruleId);

            using (var dbContext = new HouseOfClansEntities())
            {
                dbContext.Rules.Attach(deleteRule);
                dbContext.Rules.Remove(deleteRule);
                isDeleted = dbContext.SaveChanges() > 0;
            }

            return(isDeleted);
        }
Exemple #15
0
        /// <summary>
        /// Deletes a UserBlackList
        /// </summary>
        public static bool Delete(int blacklistId)
        {
            bool          isDeleted       = false;
            UserBlackList deleteBlacklist = BlacklistManager.SelectByBlacklistId(blacklistId);

            using (var dbContext = new HouseOfClansEntities())
            {
                dbContext.UserBlackLists.Attach(deleteBlacklist);
                dbContext.UserBlackLists.Remove(deleteBlacklist);
                isDeleted = dbContext.SaveChanges() > 0;
            }

            return(isDeleted);
        }
        /// <summary>
        /// Deletes a ClanGroup
        /// </summary>
        public static bool Delete(int clanGroupId)
        {
            bool      isDeleted       = false;
            ClanGroup deleteClanGroup = ClanGroupManager.SelectByClanGroupId(clanGroupId);

            using (var dbContext = new HouseOfClansEntities())
            {
                dbContext.ClanGroups.Attach(deleteClanGroup);
                dbContext.ClanGroups.Remove(deleteClanGroup);
                isDeleted = dbContext.SaveChanges() > 0;
            }

            return(isDeleted);
        }
        /// <summary>
        /// Inserts a new Action Log entry
        /// </summary>
        private static void Log(Enums.Action action, int userId, string objectChanged, string propertyChanged, string oldValue, string newValue)
        {
            ActionLog entry = new ActionLog();

            entry.actionId        = (short)action;
            entry.userClanId      = userId;
            entry.objectChanged   = objectChanged;
            entry.propertyChanged = propertyChanged;
            entry.oldValue        = oldValue;
            entry.newValue        = newValue;
            entry.addedOn         = DateTime.Now;

            using (var dbContext = new HouseOfClansEntities())
            {
                dbContext.ActionLogs.Add(entry);
                dbContext.SaveChanges();
            }
        }
        public static void Upsert(List <WarRanking> rankings)
        {
            using (var dbContext = new HouseOfClansEntities())
            {
                //vv The next line helps debugging. It will write to the Output window the sql statements
                //vv dbContext.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
                foreach (WarRanking ranking in rankings)
                {
                    if (ranking.id == 0)
                    {
                        ranking.addedOn = DateTime.Now;
                        dbContext.WarRankings.Add(ranking);
                    }
                    else
                    {
                        ranking.updatedOn = DateTime.Now;
                        dbContext.Entry(ranking).State = EntityState.Modified;
                    }

                    dbContext.SaveChanges();
                }
            }
        }
Exemple #19
0
        /// <summary>
        /// Inserts or Updates the Clan War Picks depending on the parameters received.
        /// </summary>
        /// <param name="clanWarPickViewModel">A ClanWarPickViewModel object, if its Id is NULL then do an Insert, else Updates.</param>
        public static void Upsert(List <ClanWarPickViewModel> clanWarPicksList)
        {
            using (var dbContext = new HouseOfClansEntities())
            {
                foreach (ClanWarPickViewModel pick in clanWarPicksList)
                {
                    ClanWarPick clanWarPick = ClanWarPicksManager.ConvertViewToModel(pick);

                    if (pick.Id == null)
                    {
                        clanWarPick.addedOn = DateTime.Now;
                        dbContext.ClanWarPicks.Add(clanWarPick);
                    }
                    else
                    {
                        clanWarPick.updatedOn = DateTime.Now;
                        dbContext.Entry(clanWarPick).State = EntityState.Modified;
                        dbContext.Entry(clanWarPick).Property(p => p.clanMemberWarPosition).IsModified = false;
                    }

                    dbContext.SaveChanges();
                }
            }
        }
Exemple #20
0
        public static void UpdateMemberWarPosition(string[] sortedPicks)
        {
            string idParsed = string.Empty;

            using (var dbContext = new HouseOfClansEntities())
            {
                for (short i = 0; i < sortedPicks.Length; i++)
                {
                    idParsed = sortedPicks[i].Replace(_clanWarPickSortedName, "");

                    ClanWarPick pick = new ClanWarPick()
                    {
                        id = int.Parse(idParsed),
                        clanMemberWarPosition = (short)(i + 1),
                        updatedOn             = DateTime.Now
                    };

                    dbContext.ClanWarPicks.Attach(pick);
                    dbContext.Entry(pick).Property(p => p.clanMemberWarPosition).IsModified = true;
                    dbContext.Entry(pick).Property(p => p.updatedOn).IsModified             = true;
                    dbContext.SaveChanges();
                }
            }
        }