public SaveResult InsertOrUpdate(ref StaticBuffDTO staticBuff)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    long       id     = staticBuff.CharacterId;
                    short      cardid = staticBuff.CardId;
                    StaticBuff entity = context.StaticBuff.FirstOrDefault(c => c.CardId == cardid && c.CharacterId == id);

                    if (entity == null)
                    {
                        staticBuff = Insert(staticBuff, context);
                        return(SaveResult.Inserted);
                    }
                    staticBuff.StaticBuffId = entity.StaticBuffId;
                    staticBuff = Update(entity, staticBuff, context);
                    return(SaveResult.Updated);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(SaveResult.Error);
            }
        }
Exemplo n.º 2
0
 public static bool ToStaticBuffDTO(StaticBuff input, StaticBuffDTO output)
 {
     if (input == null)
     {
         return(false);
     }
     output.CardId        = input.CardId;
     output.CharacterId   = input.CharacterId;
     output.RemainingTime = input.RemainingTime;
     output.StaticBuffId  = input.StaticBuffId;
     return(true);
 }
 public IEnumerable <StaticBuffDTO> LoadByCharacterId(long characterId)
 {
     using (OpenNosContext context = DataAccessHelper.CreateContext())
     {
         List <StaticBuffDTO> result = new List <StaticBuffDTO>();
         foreach (StaticBuff entity in context.StaticBuff.AsNoTracking().Where(i => i.CharacterId == characterId))
         {
             StaticBuffDTO dto = new StaticBuffDTO();
             Mapper.Mappers.StaticBuffMapper.ToStaticBuffDTO(entity, dto);
             result.Add(dto);
         }
         return(result);
     }
 }
        private static StaticBuffDTO Update(StaticBuff entity, StaticBuffDTO sb, OpenNosContext context)
        {
            if (entity != null)
            {
                Mapper.Mappers.StaticBuffMapper.ToStaticBuff(sb, entity);
                context.SaveChanges();
            }
            if (Mapper.Mappers.StaticBuffMapper.ToStaticBuffDTO(entity, sb))
            {
                return(sb);
            }

            return(null);
        }
        public static StaticBuffDTO LoadById(long sbId)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    StaticBuffDTO dto = new StaticBuffDTO();
                    if (Mapper.Mappers.StaticBuffMapper.ToStaticBuffDTO(context.StaticBuff.AsNoTracking().FirstOrDefault(s => s.StaticBuffId.Equals(sbId)), dto)) //who the f**k was so retarded and set it to respawn ?!?
                    {
                        return(dto);
                    }

                    return(null);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(null);
            }
        }
        private static StaticBuffDTO Insert(StaticBuffDTO sb, OpenNosContext context)
        {
            try
            {
                StaticBuff entity = new StaticBuff();
                Mapper.Mappers.StaticBuffMapper.ToStaticBuff(sb, entity);
                context.StaticBuff.Add(entity);
                context.SaveChanges();
                if (Mapper.Mappers.StaticBuffMapper.ToStaticBuffDTO(entity, sb))
                {
                    return(sb);
                }

                return(null);
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(null);
            }
        }