예제 #1
0
 public MapMonsterDTO Insert(MapMonsterDTO mapmonster)
 {
     using (var context = DataAccessHelper.CreateContext())
     {
         MapMonster entity = Mapper.Map <MapMonster>(mapmonster);
         context.mapmonster.Add(entity);
         context.SaveChanges();
         return(Mapper.Map <MapMonsterDTO>(entity));
     }
 }
예제 #2
0
 public void Insert(List <MapMonsterDTO> monsters)
 {
     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();
     }
 }
예제 #3
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);
     }
 }
        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);
            }
        }