public void Insert(List <PortalDTO> portals)
 {
     try
     {
         using (var context = DataAccessHelper.CreateContext())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             foreach (PortalDTO Item in portals)
             {
                 Portal entity = _mapper.Map <Portal>(Item);
                 context.Portal.Add(entity);
             }
             context.Configuration.AutoDetectChangesEnabled = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Exemple #2
0
 public void Insert(List <DropDTO> drops)
 {
     try
     {
         using (var context = DataAccessHelper.CreateContext())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             foreach (DropDTO Drop in drops)
             {
                 Drop entity = _mapper.Map <Drop>(Drop);
                 context.Drop.Add(entity);
             }
             context.Configuration.AutoDetectChangesEnabled = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Exemple #3
0
        public SaveResult InsertOrUpdate(ref RespawnDTO respawn)
        {
            using (var context = DataAccessHelper.CreateContext())
            {
                long    CharacterId = respawn.CharacterId;
                short   RespawnType = respawn.RespawnType;
                Respawn entity      = context.Respawn.FirstOrDefault(c => c.RespawnType.Equals(RespawnType) && c.CharacterId.Equals(CharacterId));

                if (entity == null) //new entity
                {
                    respawn = Insert(respawn, context);
                    return(SaveResult.Inserted);
                }
                else //existing entity
                {
                    respawn.RespawnId = entity.RespawnId;
                    respawn           = Update(entity, respawn, context);
                    return(SaveResult.Updated);
                }
            }
        }
 public void Insert(List <SkillDTO> skills)
 {
     try
     {
         using (var context = DataAccessHelper.CreateContext())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             foreach (SkillDTO Skill in skills)
             {
                 Skill entity = _mapper.Map <Skill>(Skill);
                 context.Skill.Add(entity);
             }
             context.Configuration.AutoDetectChangesEnabled = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Exemple #5
0
        public IEnumerable <InventoryDTO> InsertOrUpdate(IEnumerable <InventoryDTO> inventories)
        {
            try
            {
                IList <InventoryDTO> results = new List <InventoryDTO>();
                using (var context = DataAccessHelper.CreateContext())
                {
                    foreach (InventoryDTO inventory in inventories)
                    {
                        results.Add(InsertOrUpdate(context, inventory));
                    }
                }

                return(results);
            }
            catch (Exception e)
            {
                Logger.Log.Error(String.Format(Language.Instance.GetMessageFromKey("UPDATE_ERROR"), e.Message), e);
                return(Enumerable.Empty <InventoryDTO>());
            }
        }
 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);
     }
 }
        public DeleteResult Delete(int penaltylogid)
        {
            try
            {
                using (var context = DataAccessHelper.CreateContext())
                {
                    PenaltyLog PenaltyLog = context.PenaltyLog.FirstOrDefault(c => c.PenaltyLogId.Equals(penaltylogid));

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

                    return(DeleteResult.Deleted);
                }
            }
            catch (Exception e)
            {
                Logger.Log.Error(String.Format(Language.Instance.GetMessageFromKey("DELETE_PENALTYLOG_ERROR"), penaltylogid, e.Message), e);
                return(DeleteResult.Error);
            }
        }
Exemple #8
0
        public DeleteResult Delete(long accountId)
        {
            try
            {
                using (var context = DataAccessHelper.CreateContext())
                {
                    Account Account = context.Account.FirstOrDefault(c => c.AccountId.Equals(accountId));

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

                    return(DeleteResult.Deleted);
                }
            }
            catch (Exception e)
            {
                Logger.Log.Error(String.Format(Language.Instance.GetMessageFromKey("DELETE_ACCOUNT_ERROR"), accountId, e.Message), e);
                return(DeleteResult.Error);
            }
        }
        public DeleteResult DeleteById(int itemId)
        {
            try
            {
                using (var context = DataAccessHelper.CreateContext())
                {
                    ShopItem Item = context.ShopItem.FirstOrDefault(i => i.ShopItemId.Equals(itemId));

                    if (Item != null)
                    {
                        context.ShopItem.Remove(Item);
                        context.SaveChanges();
                    }

                    return(DeleteResult.Deleted);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(DeleteResult.Error);
            }
        }
Exemple #10
0
 public DeleteResult DeleteFromSlotAndType(long characterId, short slot, InventoryType type)
 {
     try
     {
         using (var context = DataAccessHelper.CreateContext())
         {
             Inventory    inv     = context.Inventory.FirstOrDefault(i => i.Slot.Equals(slot) && i.Type.Equals(type) && i.CharacterId.Equals(characterId));
             ItemInstance invItem = context.ItemInstance.FirstOrDefault(i => i.Inventory.Id == inv.Id);
             if (inv != null)
             {
                 context.Inventory.Remove(inv);
                 context.ItemInstance.Remove(invItem);
                 context.SaveChanges();
             }
             return(DeleteResult.Deleted);
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
         return(DeleteResult.Error);
     }
 }
Exemple #11
0
 public override DeleteResult Delete(Guid id)
 {
     try
     {
         using (var context = DataAccessHelper.CreateContext())
         {
             Inventory    entity   = context.Set <Inventory>().FirstOrDefault(i => i.Id.Equals(id));
             ItemInstance instance = context.Set <ItemInstance>().FirstOrDefault(i => i.Id.Equals(id));
             if (entity != null)
             {
                 context.Set <Inventory>().Remove(entity);
                 context.Set <ItemInstance>().Remove(instance);
                 context.SaveChanges();
             }
             return(DeleteResult.Deleted);
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
         return(DeleteResult.Error);
     }
 }
Exemple #12
0
        public DeleteResult DeleteById(long mailId)
        {
            try
            {
                using (var context = DataAccessHelper.CreateContext())
                {
                    Mail mail = context.Mail.First(i => i.MailId.Equals(mailId));

                    if (mail != null)
                    {
                        context.Mail.Remove(mail);
                        context.SaveChanges();
                    }

                    return(DeleteResult.Deleted);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(DeleteResult.Error);
            }
        }
        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);
            }
        }
Exemple #14
0
        public int IsReputHero(long characterId)
        {
            using (var context = DataAccessHelper.CreateContext())
            {
                List <Character> heroes = context.character.Where(c => c.account.Authority != (short)AuthorityType.Admin).OrderByDescending(c => c.Reput).Take(43).ToList();

                int i = 0;
                foreach (Character c in heroes)
                {
                    i++;
                    if (c.CharacterId == characterId)
                    {
                        if (i == 1)
                        {
                            return(5);
                        }
                        if (i == 2)
                        {
                            return(4);
                        }
                        if (i == 3)
                        {
                            return(3);
                        }
                        if (i <= 13)
                        {
                            return(2);
                        }
                        if (i <= 43)
                        {
                            return(1);
                        }
                    }
                }
                return(0);
            }
        }
Exemple #15
0
 public SaveResult InsertOrUpdate(ref InventoryDTO inventory)
 {
     try
     {
         using (var context = DataAccessHelper.CreateContext())
         {
             long      InventoryId = inventory.InventoryId;
             byte      Type        = inventory.Type;
             short     Slot        = inventory.Slot;
             long      CharacterId = inventory.CharacterId;
             Inventory entity      = context.inventory.SingleOrDefault(c => c.InventoryId == InventoryId);
             if (entity == null) //new entity
             {
                 Inventory delete = context.inventory.FirstOrDefault(s => s.CharacterId == CharacterId && s.Slot == Slot && s.Type == Type);
                 if (delete != null)
                 {
                     InventoryItem deleteItem = context.inventoryitem.FirstOrDefault(s => s.inventory.InventoryId == delete.InventoryId);
                     context.inventoryitem.Remove(deleteItem);
                     context.inventory.Remove(delete);
                 }
                 inventory = Insert(inventory, context);
                 return(SaveResult.Inserted);
             }
             else //existing entity
             {
                 entity.inventoryitem = context.inventoryitem.SingleOrDefault(c => c.inventory.InventoryId == entity.InventoryId);
                 inventory            = Update(entity, inventory, context);
                 return(SaveResult.Updated);
             }
         }
     }
     catch (Exception e)
     {
         Logger.Log.ErrorFormat(Language.Instance.GetMessageFromKey("UPDATE_ERROR"), e.Message);
         return(SaveResult.Error);
     }
 }
Exemple #16
0
        public IEnumerable <CharacterSkillDTO> InsertOrUpdate(IEnumerable <CharacterSkillDTO> characterSkills)
        {
            try
            {
                List <CharacterSkillDTO> returnSkills = new List <CharacterSkillDTO>();

                using (var context = DataAccessHelper.CreateContext())
                {
                    foreach (CharacterSkillDTO skill in characterSkills)
                    {
                        CharacterSkillDTO returnSkill = skill;
                        SaveResult        result      = InsertOrUpdate(ref returnSkill, context);
                        returnSkills.Add(returnSkill);
                    }
                }

                return(returnSkills);
            }
            catch (Exception e)
            {
                Logger.Log.Error(String.Format(Language.Instance.GetMessageFromKey("UPDATE_ERROR"), e.Message), e);
                return(Enumerable.Empty <CharacterSkillDTO>());
            }
        }