public static void Log <T>(Enums.Action action, int userId, List <ActionLog> changes) { foreach (ActionLog change in changes) { ActionLogManager.Log <T>(action, userId, change.propertyChanged, change.oldValue, change.newValue); } }
/// <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); }