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); }
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()); } } }
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"); } } }
public IEnumerable <Chain> GetChains() { using (var context = new PriceCompareDbContext()) { var chainRep = new ChainRepository(context); return(chainRep.GetChains()); } }
public async Task UpdateItemInCartAsync(long itemCode, int itemCount) { using (var context = new PriceCompareDbContext()) { var cartRep = new CartRepository(context); await cartRep.UpdateItemCountAsync(itemCode, itemCount); } }
public async Task <Price> GetItemPriceByCodeAsync(long itemCode) { using (var context = new PriceCompareDbContext()) { var priceRep = new PriceRepository(context); return(await priceRep.GetItemPriceByCodeAsync(itemCode)); } }
public async Task AddItemToCartAsync(long itemCode) { using (var context = new PriceCompareDbContext()) { var managerRep = new ManagerRepository(context); await managerRep.AddItemToCartAsync(itemCode, User.CartId); } }
public async Task <IEnumerable <ItemCart> > GetCartItemsAsync() { using (var context = new PriceCompareDbContext()) { var cartRep = new CartRepository(context); return(await cartRep.GetCartItemsAsync(User.CartId)); } }
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)); } }
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)); } }
public async Task RemoveItemFromCartAsync(long itemCode) { using (var context = new PriceCompareDbContext()) { var cartRep = new CartRepository(context); await cartRep.RemoveItemFromCartAsync(itemCode); } }
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)); } }
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)); } }
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)); } }
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); }
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); } }
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()); } } }
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()); } } }
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(); } } } }
public ChainRepository(PriceCompareDbContext context) : base(context) { }
public ManagerRepository(PriceCompareDbContext context) : base(context) { }
public ItemRepository(PriceCompareDbContext context) : base(context) { }
protected Repository(PriceCompareDbContext context) { _context = context; }