コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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);
        }