Ejemplo n.º 1
0
        private static void AddItemsAndPrices(PriceCompareDbContext context, int storeId, Item[] items)
        {
            var itemsToAdd = items.Select(
                item => new Model.Item
            {
                ItemCode        = item.ItemCode,
                ItemType        = item.ItemType,
                ItemName        = item.ItemName,
                IsWeighted      = item.IsWeighted,
                ManufactureName = item.ManufacturerName
            });
            var toAdd = itemsToAdd as List <Model.Item> ?? itemsToAdd.ToList();

            RemoveExistItems(toAdd, context.Items);
            context.Items.AddRange(toAdd);
            var pricesToAdd = items.Select(
                item => new Price
            {
                ItemCode           = item.ItemCode,
                StoreId            = storeId,
                ChainId            = item.ChainId,
                ItemPrice          = item.ItemPrice,
                ItemName           = item.ItemName,
                Quantity           = item.Quantity,
                UnitOfMeasurePrice = item.UnitOfMeasurePrice
            });

            context.Prices.AddRange(pricesToAdd);
        }
Ejemplo n.º 2
0
        private void button3_Click_2(object sender, EventArgs e)
        {
            using (var context = new PriceCompareDbContext())
            {
                try
                {
                    context.Chains.Add(new Chain {
                        ChainId = "7290058140886", ChainName = "רמי לוי"
                    });
                    context.Chains.Add(new Chain {
                        ChainId = "7290027600007", ChainName = "שופרסל"
                    });
                    context.Chains.Add(new Chain {
                        ChainId = "7290873255550", ChainName = "טיב טעם"
                    });

                    context.SaveChanges();
                    MessageBox.Show(@"Added");
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.ToString());
                }
            }
        }
Ejemplo n.º 3
0
        private async void btnRegister_Click(object sender, EventArgs e)
        {
            var name     = txtNameReg.Text;
            var username = txtUsernameReg.Text;
            var password = txtPasswordReg.Text;

            if (name.Length == 0 || username.Length == 0 || password.Length == 0)
            {
                MessageBox.Show(@"Please enter a valid input");
                return;
            }
            using (var context = new PriceCompareDbContext())
            {
                var userRep = new UserRepository(context);
                var isExist = await userRep.IsUserExist(username);

                if (isExist)
                {
                    MessageBox.Show(@"Username exist! Use another username");
                }
                else
                {
                    var user = userRep.AddUser(name, username, password);
                    MessageBox.Show(user == null ? @"registration failed!" : @"registration successed");
                }
            }
        }
Ejemplo n.º 4
0
 public IEnumerable <Chain> GetChains()
 {
     using (var context = new PriceCompareDbContext())
     {
         var chainRep = new ChainRepository(context);
         return(chainRep.GetChains());
     }
 }
Ejemplo n.º 5
0
 public async Task UpdateItemInCartAsync(long itemCode, int itemCount)
 {
     using (var context = new PriceCompareDbContext())
     {
         var cartRep = new CartRepository(context);
         await cartRep.UpdateItemCountAsync(itemCode, itemCount);
     }
 }
Ejemplo n.º 6
0
 public async Task <Price> GetItemPriceByCodeAsync(long itemCode)
 {
     using (var context = new PriceCompareDbContext())
     {
         var priceRep = new PriceRepository(context);
         return(await priceRep.GetItemPriceByCodeAsync(itemCode));
     }
 }
Ejemplo n.º 7
0
 public async Task AddItemToCartAsync(long itemCode)
 {
     using (var context = new PriceCompareDbContext())
     {
         var managerRep = new ManagerRepository(context);
         await managerRep.AddItemToCartAsync(itemCode, User.CartId);
     }
 }
Ejemplo n.º 8
0
 public async Task <IEnumerable <ItemCart> > GetCartItemsAsync()
 {
     using (var context = new PriceCompareDbContext())
     {
         var cartRep = new CartRepository(context);
         return(await cartRep.GetCartItemsAsync(User.CartId));
     }
 }
Ejemplo n.º 9
0
 public async Task <IEnumerable <Price> > GetItemsInStoreByStoreWithNameIdAsync(int storeId, string text, long chainId)
 {
     using (var context = new PriceCompareDbContext())
     {
         var priceRep = new PriceRepository(context);
         return(await priceRep.GetItemsInStoreByStoreWithNameIdAsync(storeId, text, chainId));
     }
 }
Ejemplo n.º 10
0
 public async Task <IEnumerable <Price> > GetItemsPricesInStoreSortedAscAsync(int storeId, long chainId)
 {
     using (var context = new PriceCompareDbContext())
     {
         var priceRep = new PriceRepository(context);
         return(await priceRep.GetItemsPricesInStoreSortedAscAsync(storeId, chainId));
     }
 }
Ejemplo n.º 11
0
 public async Task RemoveItemFromCartAsync(long itemCode)
 {
     using (var context = new PriceCompareDbContext())
     {
         var cartRep = new CartRepository(context);
         await cartRep.RemoveItemFromCartAsync(itemCode);
     }
 }
Ejemplo n.º 12
0
 public async Task <IEnumerable <Item> > GetItemsByNameAsync(string itemName)
 {
     if (itemName == null)
     {
         throw new ArgumentNullException();
     }
     using (var context = new PriceCompareDbContext())
     {
         var managerReop = new ManagerRepository(context);
         return(await managerReop.GetItemsByNameAsync(itemName));
     }
 }
Ejemplo n.º 13
0
 public async Task <IEnumerable <Item> > GetItemsWithManufactureNameAsync(string manufactureName)
 {
     if (manufactureName == null)
     {
         throw new ArgumentNullException(nameof(manufactureName));
     }
     using (var context = new PriceCompareDbContext())
     {
         var managerRep = new ManagerRepository(context);
         return(await managerRep.GetItemsWithManufactureNameAsync(manufactureName));
     }
 }
Ejemplo n.º 14
0
 public IEnumerable <Store> GetStoresByChainId(string chainId)
 {
     if (chainId == null)
     {
         throw new ArgumentNullException(nameof(chainId));
     }
     using (var context = new PriceCompareDbContext())
     {
         var chainRep = new ChainRepository(context);
         return(chainRep.GetStoresByChainId(chainId));
     }
 }
Ejemplo n.º 15
0
        private static void AddStores(PriceCompareDbContext context, IEnumerable <Store> stores)
        {
            var storesToAdd = stores.Select(
                store => new Model.Store
            {
                BikoretNo = store.BikoretNo,
                ChainId   = store.ChainId.ToString(),
                StoreId   = store.StoreId,
                StoreName = store.StoreName,
                StoreType = store.StoreType
            });

            context.Stores.AddRange(storesToAdd);
        }
Ejemplo n.º 16
0
        public async Task <IEnumerable <Tuple <ItemCart, Price> > > GetItemsInCartPricesByStoreAsync(long chainId, int storeId, IEnumerable <ItemCart> items)
        {
            using (var context = new PriceCompareDbContext())
            {
                var priceRep         = new PriceRepository(context);
                var allPricesInStore = await priceRep.GetPricesByStoreIdAsync(storeId, chainId);

                var pricesInStore = allPricesInStore.ToArray();
                if (pricesInStore.Count() != 0)
                {
                    return(await Task.Run(() => items.ToList()
                                          .Select(item => new Tuple <ItemCart, Price>(item, pricesInStore
                                                                                      .FirstOrDefault(price => price.ItemCode == item.ItemCode)))));
                }
                return(null);
            }
        }
Ejemplo n.º 17
0
        private async void button6_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            using (var context = new PriceCompareDbContext())
            {
                try
                {
                    var storeCollection = (StoresCollection) new StoresXmlParser().Parse(new StreamReader(openFileDialog1.FileName));
                    var stores          = storeCollection.Stores;
                    AddStores(context, stores);
                    await context.SaveChangesAsync();

                    MessageBox.Show(@"Done");
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.ToString());
                }
            }
        }
Ejemplo n.º 18
0
        private async void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            using (var context = new PriceCompareDbContext())
            {
                try
                {
                    var itemCollection = (ShofesalItemsCollection) new ShofersalPriceXmlParser().Parse(new StreamReader(openFileDialog1.FileName));
                    var items          = itemCollection.Items;
                    AddItemsAndPrices(context, itemCollection.StoreId, items);
                    await context.SaveChangesAsync();

                    MessageBox.Show(@"Done");
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.ToString());
                }
            }
        }
Ejemplo n.º 19
0
        private async void btnLogin_Click(object sender, EventArgs e)
        {
            var username = txtUsernameLogin.Text;
            var password = txtPasswordLogin.Text;

            if (username.Length == 0 || password.Length == 0)
            {
                MessageBox.Show(@"Please enter a valid input");
                return;
            }
            using (var context = new PriceCompareDbContext())
            {
                var userRep = new UserRepository(context);
                var isExist = await userRep.IsUserExist(username);

                if (!isExist)
                {
                    MessageBox.Show(@"Username does not exist!");
                }
                else
                {
                    var result = await userRep.CheckUserPassword(username, password);

                    if (!result)
                    {
                        MessageBox.Show(@"Wrong password!");
                    }
                    else
                    {
                        var user = await userRep.GetUser(username);

                        Hide();
                        new MainWindow(user).ShowDialog();
                    }
                }
            }
        }
Ejemplo n.º 20
0
 public ChainRepository(PriceCompareDbContext context) : base(context)
 {
 }
 public ManagerRepository(PriceCompareDbContext context) : base(context)
 {
 }
Ejemplo n.º 22
0
 public ItemRepository(PriceCompareDbContext context) : base(context)
 {
 }
Ejemplo n.º 23
0
 protected Repository(PriceCompareDbContext context)
 {
     _context = context;
 }