Ejemplo n.º 1
0
        public SaveResult InsertOrUpdate(ref InventoryDTO inventory)
        {
            try
            {
                using (var context = DataAccessHelper.CreateContext())
                {
                    long characterId = inventory.CharacterId;
                    short slot = inventory.Slot;
                    short type = inventory.Type;
                    Inventory entity = context.inventory.SingleOrDefault(c => c.Type.Equals(type) && c.Slot.Equals(slot) && c.CharacterId.Equals(characterId));

                    if (entity == null) //new entity
                    {
                        inventory = Insert(inventory, context);
                        return SaveResult.Inserted;
                    }
                    else //existing entity
                    {
                        inventory.InventoryId = entity.InventoryId;
                        inventory = Update(entity, inventory, context);
                        return SaveResult.Updated;
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Log.ErrorFormat(Language.Instance.GetMessageFromKey("UPDATE_ACCOUNT_ERROR"), inventory.InventoryId, e.Message);
                return SaveResult.Error;
            }
        }
Ejemplo n.º 2
0
 private InventoryDTO Insert(InventoryDTO inventory, OpenNosContainer context)
 {
     Inventory entity = new Inventory()
     {
         CharacterId = inventory.CharacterId,
         InventoryItemId = inventory.InventoryItemId,
         Slot = inventory.Slot,
         Type = inventory.Type,
     };
     context.inventory.Add(entity);
     context.SaveChanges();
     return Mapper.Map<InventoryDTO>(entity);
 }
Ejemplo n.º 3
0
        private InventoryDTO Update(Inventory entity, InventoryDTO inventory, OpenNosContainer context)
        {
            using (context)
            {
                var result = context.inventory.SingleOrDefault(c => c.InventoryId == inventory.InventoryId);
                if (result != null)
                {
                    result = Mapper.Map<InventoryDTO, Inventory>(inventory, entity);
                    context.SaveChanges();
                }
            }

            return Mapper.Map<InventoryDTO>(entity);
        }
Ejemplo n.º 4
0
 private InventoryDTO Insert(InventoryDTO inventory, OpenNosContainer context)
 {
     Inventory entity = Mapper.Map<Inventory>(inventory);
     context.inventory.Add(entity);
     context.SaveChanges();
     return Mapper.Map<InventoryDTO>(entity);
 }