示例#1
0
        public Task <Guid> CreateShopGroup(string connectionId, string shopId)
        {
            var id = Guid.NewGuid();

            _shopGroupInfo[id] = new ShopGroup()
            {
                shopConnectionId = connectionId,
                shopId           = shopId
            };

            return(Task.FromResult(id));
        }
示例#2
0
        private static List <ShopGroup> ImrportGroups(string[] shops)
        {
            var groupsList = new List <string>();

            foreach (var shop in shops)
            {
                var groupsForOneItem1 = shop.Split(';')[2];
                var groupsForOneItem2 = shop.Split(';')[3];
                groupsList.Add(groupsForOneItem1);
                groupsList.Add(groupsForOneItem2);
            }
            var groupedList = groupsList.GroupBy(x => x).Select(x => x.Key).ToList();

            groupedList = groupedList.Where(g => !string.IsNullOrWhiteSpace(g)).Select(s => s).ToList();
            var domainList = new List <ShopGroup>();

            using (RaterPriceContext context = RaterPriceContext.Create())
            {
                foreach (var gr in groupedList)
                {
                    var domainItem = new ShopGroup()
                    {
                        Name = gr.Trim()
                    };
                    if (!context.ShopGroups.Any(g => g.Name.Equals(domainItem.Name)))
                    {
                        domainItem.Id = context.ShopGroups.Add(domainItem).Id;
                        context.SaveChanges();
                        Console.WriteLine("Group has been imported: " + domainItem.Name);
                    }
                    else
                    {
                        domainItem.Id = context.ShopGroups.Where(p => p.Name.Equals(domainItem.Name)).Select(p => p.Id).First();
                    }
                    domainList.Add(domainItem);
                }
            }
            return(domainList);
        }