Esempio n. 1
0
 public void Insert(List <ShopDTO> shops)
 {
     try
     {
         using (OpenNosContext context = DataAccessHelper.CreateContext())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             foreach (ShopDTO item in shops)
             {
                 Shop entity = new Shop();
                 Mapper.Mappers.ShopMapper.ToShop(item, entity);
                 context.Shop.Add(entity);
             }
             context.Configuration.AutoDetectChangesEnabled = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Esempio n. 2
0
        public DeleteResult DeleteByEquipmentSerialId(Guid id)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    List <CellonOption> deleteentities = context.CellonOption.Where(s => s.EquipmentSerialId == id).ToList();
                    if (deleteentities.Count != 0)
                    {
                        context.CellonOption.RemoveRange(deleteentities);
                        context.SaveChanges();
                    }

                    return(DeleteResult.Deleted);
                }
            }
            catch (Exception e)
            {
                Logger.Error(string.Format(Language.Instance.GetMessageFromKey("DELETE_ERROR"), id, e.Message), e);
                return(DeleteResult.Error);
            }
        }
Esempio n. 3
0
 public void Insert(List <DropDTO> drops)
 {
     try
     {
         using (OpenNosContext context = DataAccessHelper.CreateContext())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             foreach (DropDTO drop in drops)
             {
                 Drop entity = new Drop();
                 Mapper.Mappers.DropMapper.ToDrop(drop, entity);
                 context.Drop.Add(entity);
             }
             context.Configuration.AutoDetectChangesEnabled = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Esempio n. 4
0
 public void Insert(List <MapTypeMapDTO> mapTypeMaps)
 {
     try
     {
         using (OpenNosContext context = DataAccessHelper.CreateContext())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             foreach (MapTypeMapDTO mapTypeMap in mapTypeMaps)
             {
                 MapTypeMap entity = new MapTypeMap();
                 Mapper.Mapper.Instance.MapTypeMapMapper.ToMapTypeMap(mapTypeMap, entity);
                 context.MapTypeMap.Add(entity);
             }
             context.Configuration.AutoDetectChangesEnabled = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Esempio n. 5
0
 public void Insert(List <ComboDTO> combos)
 {
     try
     {
         using (OpenNosContext context = DataAccessHelper.CreateContext())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             foreach (ComboDTO combo in combos)
             {
                 Combo entity = new Combo();
                 Mapper.Mapper.Instance.ComboMapper.ToCombo(combo, entity);
                 context.Combo.Add(entity);
             }
             context.Configuration.AutoDetectChangesEnabled = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
 public void Insert(List <RespawnMapTypeDTO> respawnMapTypes)
 {
     try
     {
         using (OpenNosContext context = DataAccessHelper.CreateContext())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             foreach (RespawnMapTypeDTO RespawnMapType in respawnMapTypes)
             {
                 RespawnMapType entity = new RespawnMapType();
                 Mapper.Mapper.Instance.RespawnMapTypeMapper.ToRespawnMapType(RespawnMapType, entity);
                 context.RespawnMapType.Add(entity);
             }
             context.Configuration.AutoDetectChangesEnabled = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Esempio n. 7
0
        private static CharacterRelationDTO update(CharacterRelation entity, CharacterRelationDTO relation, OpenNosContext context)
        {
            if (entity != null)
            {
                try
                {
                    Mapper.Mappers.CharacterRelationMapper.ToCharacterRelation(relation, entity);
                    context.SaveChanges();
                }
                catch (InvalidOperationException ex)
                {
                    Logger.Warn($"The Character Relation with ID:{relation.CharacterRelationId} is Wrong! Error:{ex.Message}");
                }
            }

            if (Mapper.Mappers.CharacterRelationMapper.ToCharacterRelationDTO(entity, relation))
            {
                return(relation);
            }

            return(null);
        }
Esempio n. 8
0
 public void Insert(List <NpcMonsterDTO> npcMonsters)
 {
     try
     {
         using (OpenNosContext context = DataAccessHelper.CreateContext())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             foreach (NpcMonsterDTO item in npcMonsters)
             {
                 NpcMonster entity = new NpcMonster();
                 Mapper.Mappers.NpcMonsterMapper.ToNpcMonster(item, entity);
                 context.NpcMonster.Add(entity);
             }
             context.Configuration.AutoDetectChangesEnabled = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Esempio n. 9
0
        public DeleteResult DeleteById(long mailId)
        {
            try
            {
                using (OpenNosContext 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
            {
                return(DeleteResult.Error);
            }
        }
Esempio n. 10
0
 public void Insert(IEnumerable <MapMonsterDTO> mapMonsters)
 {
     try
     {
         using (OpenNosContext context = DataAccessHelper.CreateContext())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             foreach (MapMonsterDTO monster in mapMonsters)
             {
                 MapMonster entity = new MapMonster();
                 Mapper.Mappers.MapMonsterMapper.ToMapMonster(monster, entity);
                 context.MapMonster.Add(entity);
             }
             context.Configuration.AutoDetectChangesEnabled = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Esempio n. 11
0
 public void Insert(List <BCardDTO> cards)
 {
     try
     {
         using (OpenNosContext context = DataAccessHelper.CreateContext())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             foreach (BCardDTO card in cards)
             {
                 BCard entity = new BCard();
                 Mapper.Mapper.Instance.BCardMapper.ToBCard(card, entity);
                 context.BCard.Add(entity);
             }
             context.Configuration.AutoDetectChangesEnabled = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Esempio n. 12
0
 public void Insert(List <MapNpcDTO> npcs)
 {
     try
     {
         using (OpenNosContext context = DataAccessHelper.CreateContext())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             foreach (MapNpcDTO Item in npcs)
             {
                 MapNpc entity = new MapNpc();
                 Mapper.Mappers.MapNpcMapper.ToMapNpc(Item, entity);
                 context.MapNpc.Add(entity);
             }
             context.Configuration.AutoDetectChangesEnabled = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Esempio n. 13
0
 public void Insert(List <QuestObjectiveDTO> quests)
 {
     try
     {
         using (OpenNosContext context = DataAccessHelper.CreateContext())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             foreach (QuestObjectiveDTO quest in quests)
             {
                 QuestObjective entity = new QuestObjective();
                 Mapper.Mappers.QuestObjectiveMapper.ToQuestObjective(quest, entity);
                 context.QuestObjective.Add(entity);
             }
             context.Configuration.AutoDetectChangesEnabled = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Esempio n. 14
0
 public DeleteResult DeleteGuidList(IEnumerable <Guid> guids)
 {
     using (OpenNosContext context = DataAccessHelper.CreateContext())
     {
         Guid[] enumerable = guids as Guid[] ?? guids.ToArray();
         try
         {
             foreach (Guid id in enumerable)
             {
                 ItemInstance entity = context.ItemInstance.FirstOrDefault(i => i.Id == id);
                 if (entity != null && entity.Type != InventoryType.FamilyWareHouse)
                 {
                     context.ItemInstance.Remove(entity);
                 }
             }
             context.SaveChanges();
         }
         catch (Exception ex)
         {
             Logger.LogUserEventError("DELETEGUIDLIST_EXCEPTION", "Saving Process", "Items were not deleted!", ex);
             foreach (Guid id in enumerable)
             {
                 try
                 {
                     Delete(id);
                 }
                 catch (Exception exc)
                 {
                     // TODO: Work on: statement conflicted with the REFERENCE constraint
                     //       "FK_dbo.BazaarItem_dbo.ItemInstance_ItemInstanceId". The
                     //       conflict occurred in database "opennos", table "dbo.BazaarItem",
                     //       column 'ItemInstanceId'.
                     Logger.LogUserEventError("ONSAVEDELETION_EXCEPTION", "Saving Process", $"FALLBACK FUNCTION FAILED! Detailed Item Information: Item ID = {id}", exc);
                 }
             }
         }
         return(DeleteResult.Deleted);
     }
 }
 public void Insert(List <ScriptedInstanceDTO> scriptedInstances)
 {
     try
     {
         using (OpenNosContext context = DataAccessHelper.CreateContext())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             foreach (ScriptedInstanceDTO scriptedInstance in scriptedInstances)
             {
                 ScriptedInstance entity = new ScriptedInstance();
                 Mapper.Mapper.Instance.ScriptedInstanceMapper.ToScriptedInstance(scriptedInstance, entity);
                 context.ScriptedInstance.Add(entity);
             }
             context.Configuration.AutoDetectChangesEnabled = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Esempio n. 16
0
        public DeleteResult Delete(long id)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    Mate mate = context.Mate.FirstOrDefault(c => c.MateId.Equals(id));
                    if (mate != null)
                    {
                        context.Mate.Remove(mate);
                        context.SaveChanges();
                    }

                    return(DeleteResult.Deleted);
                }
            }
            catch (Exception e)
            {
                Logger.Error(string.Format(Language.Instance.GetMessageFromKey("DELETE_MATE_ERROR"), e.Message), e);
                return(DeleteResult.Error);
            }
        }
Esempio n. 17
0
 public void Insert(List <SkillDTO> skills)
 {
     try
     {
         using (OpenNosContext context = DataAccessHelper.CreateContext())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             foreach (SkillDTO skill in skills)
             {
                 Skill entity = new Skill();
                 Mapper.Mappers.SkillMapper.ToSkill(skill, entity);
                 context.Skill.Add(entity);
             }
             context.Configuration.AutoDetectChangesEnabled = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Esempio n. 18
0
 public void Insert(List <PortalDTO> portals)
 {
     try
     {
         using (OpenNosContext context = DataAccessHelper.CreateContext())
         {
             context.Configuration.AutoDetectChangesEnabled = false;
             foreach (PortalDTO item in portals)
             {
                 Portal entity = new Portal();
                 Mapper.Mappers.PortalMapper.ToPortal(item, entity);
                 context.Portal.Add(entity);
             }
             context.Configuration.AutoDetectChangesEnabled = true;
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Esempio n. 19
0
        public DeleteResult DeleteById(long id)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    Quest deleteEntity = context.Quest.Find(id);
                    if (deleteEntity != null)
                    {
                        context.Quest.Remove(deleteEntity);
                        context.SaveChanges();
                    }

                    return(DeleteResult.Deleted);
                }
            }
            catch (Exception e)
            {
                Logger.Error(string.Format(Language.Instance.GetMessageFromKey("DELETE_ERROR"), id, e.Message), e);
                return(DeleteResult.Error);
            }
        }
Esempio n. 20
0
        private MailDTO insert(MailDTO mail, OpenNosContext context)
        {
            try
            {
                Mail entity = new Mail();
                Mapper.Mapper.Instance.MailMapper.ToMail(mail, entity);
                context.Mail.Add(entity);
                context.SaveChanges();
                if (Mapper.Mapper.Instance.MailMapper.ToMailDTO(entity, mail))
                {
                    return(mail);
                }

                return(null);
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        Logger.Error(new InvalidOperationException(message, raise));
                    }
                }
                return(null);
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(null);
            }
        }
Esempio n. 21
0
        public DeleteResult DeleteById(int mapMonsterId)
        {
            try
            {
                using (OpenNosContext 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);
            }
        }
Esempio n. 22
0
        public SkillDTO Insert(SkillDTO skill)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    Skill entity = new Skill();
                    Mapper.Mappers.SkillMapper.ToSkill(skill, entity); context.Skill.Add(entity);
                    context.SaveChanges();
                    if (Mapper.Mappers.SkillMapper.ToSkillDTO(entity, skill))
                    {
                        return(skill);
                    }

                    return(null);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(null);
            }
        }
Esempio n. 23
0
        public DeleteResult Delete(long accountId)
        {
            try
            {
                using (OpenNosContext 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.Error(string.Format(Language.Instance.GetMessageFromKey("DELETE_ACCOUNT_ERROR"), accountId, e.Message), e);
                return DeleteResult.Error;
            }
        }
Esempio n. 24
0
        public DropDTO Insert(DropDTO drop)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    Drop entity = new Drop();
                    context.Drop.Add(entity);
                    context.SaveChanges();
                    if (Mapper.Mappers.DropMapper.ToDropDTO(entity, drop))
                    {
                        return(drop);
                    }

                    return(null);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(null);
            }
        }
        public DeleteResult DeleteByMapNpcId(int mapNpcId)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    IQueryable <RecipeList> recipeLists = context.RecipeList.Where(i => i.MapNpcId == mapNpcId);

                    if (recipeLists.Any())
                    {
                        context.RecipeList.RemoveRange(recipeLists);
                        context.SaveChanges();
                    }

                    return(DeleteResult.Deleted);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(DeleteResult.Error);
            }
        }
        public DeleteResult DeleteById(long id)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    MinilandObject item = context.MinilandObject.First(i => i.MinilandObjectId.Equals(id));

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

                    return(DeleteResult.Deleted);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(DeleteResult.Error);
            }
        }
        public DeleteResult Delete(string characterName)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    Character       character       = context.Character.FirstOrDefault(c => c.Name.Equals(characterName));
                    FamilyCharacter familyCharacter = context.FamilyCharacter.FirstOrDefault(c => c.CharacterId.Equals(character.CharacterId));
                    if (character != null && familyCharacter != null)
                    {
                        context.FamilyCharacter.Remove(familyCharacter);
                        context.SaveChanges();
                    }

                    return(DeleteResult.Deleted);
                }
            }
            catch (Exception e)
            {
                Logger.Error(string.Format(Language.Instance.GetMessageFromKey("DELETE_FAMILYCHARACTER_ERROR"), e.Message), e);
                return(DeleteResult.Error);
            }
        }
Esempio n. 28
0
        public DeleteResult Delete(long familyId)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    Family fam = context.Family.FirstOrDefault(c => c.FamilyId == familyId);

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

                    return(DeleteResult.Deleted);
                }
            }
            catch (Exception e)
            {
                Logger.Error(string.Format(Language.Instance.GetMessageFromKey("DELETE_ERROR"), familyId, e.Message), e);
                return(DeleteResult.Error);
            }
        }
Esempio n. 29
0
        public DeleteResult DeleteById(int portalId)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    Portal portal = context.Portal.Single(i => i.PortalId.Equals(portalId));

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

                    return(DeleteResult.Deleted);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(DeleteResult.Error);
            }
        }
Esempio n. 30
0
        public DeleteResult Delete(long characterRelationId)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    CharacterRelation relation = context.CharacterRelation.SingleOrDefault(c => c.CharacterRelationId.Equals(characterRelationId));

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

                    return(DeleteResult.Deleted);
                }
            }
            catch (Exception e)
            {
                Logger.Error(string.Format(Language.Instance.GetMessageFromKey("DELETE_CHARACTER_ERROR"), characterRelationId, e.Message), e);
                return(DeleteResult.Error);
            }
        }