public SaveResult InsertOrUpdate(ref StaticBonusDTO staticBonus) { try { using (OpenNosContext context = DataAccessHelper.CreateContext()) { long id = staticBonus.CharacterId; StaticBonusType cardid = staticBonus.StaticBonusType; StaticBonus entity = context.StaticBonus.FirstOrDefault(c => c.StaticBonusType == cardid && c.CharacterId == id); if (entity == null) { staticBonus = Insert(staticBonus, context); return(SaveResult.Inserted); } staticBonus.StaticBonusId = entity.StaticBonusId; staticBonus = Update(entity, staticBonus, context); return(SaveResult.Updated); } } catch (Exception e) { Logger.Error(e); return(SaveResult.Error); } }
public static bool ToStaticBonusDTO(StaticBonus input, StaticBonusDTO output) { if (input == null) { return(false); } output.CharacterId = input.CharacterId; output.DateEnd = input.DateEnd; output.StaticBonusId = input.StaticBonusId; output.StaticBonusType = input.StaticBonusType; return(true); }
private static StaticBonusDTO Update(StaticBonus entity, StaticBonusDTO sb, OpenNosContext context) { if (entity != null) { Mapper.Mappers.StaticBonusMapper.ToStaticBonus(sb, entity); context.SaveChanges(); } if (Mapper.Mappers.StaticBonusMapper.ToStaticBonusDTO(entity, sb)) { return(sb); } return(null); }
public void Delete(short bonusToDelete, long characterId) { try { using (OpenNosContext context = DataAccessHelper.CreateContext()) { StaticBonus bon = context.StaticBonus.FirstOrDefault(c => c.StaticBonusType == (StaticBonusType)bonusToDelete && c.CharacterId == characterId); if (bon != null) { context.StaticBonus.Remove(bon); context.SaveChanges(); } } } catch (Exception e) { Logger.Error(string.Format(Language.Instance.GetMessageFromKey("DELETE_ERROR"), bonusToDelete, e.Message), e); } }
private static StaticBonusDTO Insert(StaticBonusDTO sb, OpenNosContext context) { try { StaticBonus entity = new StaticBonus(); Mapper.Mappers.StaticBonusMapper.ToStaticBonus(sb, entity); context.StaticBonus.Add(entity); context.SaveChanges(); if (Mapper.Mappers.StaticBonusMapper.ToStaticBonusDTO(entity, sb)) { return(sb); } return(null); } catch (Exception e) { Logger.Error(e); return(null); } }