예제 #1
0
 public MapMonsterDTO Insert(MapMonsterDTO mapMonster)
 {
     try
     {
         using (var context = DataAccessHelper.CreateContext())
         {
             MapMonster entity = _mapper.Map <MapMonster>(mapMonster);
             context.MapMonster.Add(entity);
             context.SaveChanges();
             return(_mapper.Map <MapMonsterDTO>(entity));
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
         return(null);
     }
 }
예제 #2
0
 public void Insert(List <MapMonsterDTO> monsters)
 {
     try
     {
         using (var context = DataAccessHelper.CreateContext())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             foreach (MapMonsterDTO monster in monsters)
             {
                 MapMonster entity = _mapper.Map <MapMonster>(monster);
                 context.MapMonster.Add(entity);
             }
             context.Configuration.AutoDetectChangesEnabled = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
예제 #3
0
        public DeleteResult DeleteById(int mapMonsterId)
        {
            try
            {
                using (var context = DataAccessHelper.CreateContext())
                {
                    MapMonster monster = context.MapMonster.First(i => i.MapMonsterId.Equals(mapMonsterId));

                    if (monster != null)
                    {
                        context.MapMonster.Remove(monster);
                        context.SaveChanges();
                    }

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