示例#1
0
        private static IEnumerable <Common.Models.Item> ConvertItems(IEnumerable <Item> items, int startId, int endId)
        {
            var newItems      = new List <Common.Models.Item>();
            var existingItems = new List <Common.Models.Item>();

            using (var session = _sessionFactory.OpenSession())
                using (var transaction = session.BeginTransaction())
                {
                    try
                    {
                        existingItems = session.Query <Common.Models.Item>().Where(a => a.Id >= startId && a.Id <= endId).ToList();
                        transaction.Commit();
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        throw;
                    }
                }

            foreach (var item in items)
            {
                var newItem = new Common.Models.Item
                {
                    Id              = item.Id,
                    BuyPrice        = item.BuyPrice,
                    HeroicTooltip   = item.HeroicTooltip,
                    ItemLevel       = item.ItemLevel,
                    Name            = item.Name,
                    NameDescription = item.NameDescription,
                    Quality         = item.Quality,
                    SellPrice       = item.SellPrice,
                    Upgradable      = item.Upgradable,
                    Description     = item.Description,
                    Icon            = item.Icon
                };

                if (existingItems.Any(a => a.Id == item.Id))
                {
                    newItem = existingItems.FirstOrDefault(a => a.Id == item.Id);
                }

                newItems.Add(newItem);
            }

            return(newItems);
        }
示例#2
0
        private static IEnumerable<Common.Models.Item> ConvertItems(IEnumerable<Item> items, int startId, int endId)
        {
            var newItems = new List<Common.Models.Item>();
            var existingItems = new List<Common.Models.Item>();
            using (var session = _sessionFactory.OpenSession())
            using (var transaction = session.BeginTransaction())
            {
                try
                {
                    existingItems = session.Query<Common.Models.Item>().Where(a => a.Id >= startId && a.Id <= endId).ToList();
                    transaction.Commit();
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    throw;
                }
            }

            foreach (var item in items)
            {
                var newItem = new Common.Models.Item
                {
                    Id = item.Id,
                    BuyPrice = item.BuyPrice,
                    HeroicTooltip = item.HeroicTooltip,
                    ItemLevel = item.ItemLevel,
                    Name = item.Name,
                    NameDescription = item.NameDescription,
                    Quality = item.Quality,
                    SellPrice = item.SellPrice,
                    Upgradable = item.Upgradable,
                    Description = item.Description,
                    Icon = item.Icon
                };

                if (existingItems.Any(a => a.Id == item.Id))
                    newItem = existingItems.FirstOrDefault(a => a.Id == item.Id);

                newItems.Add(newItem);
            }

            return newItems;
        }