public void Add(InternetShopFilter filter) { FilesProvider.OpenWriter("InternetShop"); InternetShop newCollection = new InternetShop(); if (filter.Id.HasValue) { newCollection.Id = (int)filter.Id; } if (!string.IsNullOrEmpty(filter.Name)) { newCollection.Name = filter.Name; } if (!string.IsNullOrEmpty(filter.Category)) { newCollection.Category = filter.Category; } if (!string.IsNullOrEmpty(filter.Price)) { newCollection.Price = filter.Price; } FilesProvider.WriteMusicCollection(newCollection); FilesProvider.CloseWriter(); }
public void Add(InternetShopFilter filter) { DatabaseProvider.CreateConnectionAndCommand(); // string cmd = "INSERT INTO Names (id, Name, Category, Price) VALUES "; cmd = cmd + "("; List <string> valueComponents = new List <string>(); if (filter.Id.HasValue) { valueComponents.Add(filter.Id.ToString()); } if (!string.IsNullOrEmpty(filter.Name)) { valueComponents.Add(string.Format("'{0}'", filter.Name)); } if (!string.IsNullOrEmpty(filter.Category)) { valueComponents.Add(string.Format("'{0}'", filter.Category)); } if (!string.IsNullOrEmpty(filter.Price)) { valueComponents.Add(string.Format("'{0}'", filter.Price)); } string join = string.Join(", ", valueComponents); cmd = cmd + join; cmd = cmd + ");"; DatabaseProvider.ExecuteCommand(cmd); DatabaseProvider.CloseConnection(); }
public void Update(InternetShopFilter filter) { DatabaseProvider.CreateConnectionAndCommand(); string cmd = "UPDATE Names SET "; List <string> columnsToUpdate = new List <string>(); if (!string.IsNullOrEmpty(filter.Name)) { columnsToUpdate.Add(string.Format("Name = '{0}'", filter.Name)); } if (!string.IsNullOrEmpty(filter.Category)) { columnsToUpdate.Add(string.Format("Category = '{0}'", filter.Category)); } if (!string.IsNullOrEmpty(filter.Price)) { columnsToUpdate.Add(string.Format("Price = '{0}'", filter.Price)); } string where = string.Format(" WHERE id = {0};", filter.Id); cmd = cmd + string.Join(", ", columnsToUpdate.ToArray()) + where; DatabaseProvider.ExecuteCommand(cmd); DatabaseProvider.CloseConnection(); }
public void Delete(InternetShopFilter filter) { DatabaseProvider.CreateConnectionAndCommand(); string cmd = string.Format("DELETE FROM Names WHERE Id = {0}", filter.Id); DatabaseProvider.ExecuteCommand(cmd); DatabaseProvider.CloseConnection(); }
void getInternetShop() { IInternetShopRepository InternetShopRepo = factory.GetInternetShopRepository(); InternetShopFilter filter = new InternetShopFilter(); menu.EmptyRows(1); List <InternetShop> chosenCollections = new List <InternetShop>(InternetShopRepo.Get(filter)); // console output showInternetShop(chosenCollections); }
public List <InternetShop> Get(InternetShopFilter filter) { List <InternetShop> ResultInternetShop = new List <InternetShop>(); DatabaseProvider.CreateConnectionAndCommand(); // string cmd = "SELECT * FROM Names"; List <string> conditions = new List <string>(); // if (filter.Id.HasValue) { conditions.Add("Id = " + filter.Id.ToString()); } if (!string.IsNullOrEmpty(filter.Name)) { conditions.Add(string.Format("Name = '{0}'", filter.Name)); } if (!string.IsNullOrEmpty(filter.Category)) { conditions.Add(string.Format("Category = '{0}'", filter.Category)); } if (!string.IsNullOrEmpty(filter.Price)) { conditions.Add(string.Format("Price = '{0}'", filter.Price)); } if (conditions.Count() > 0) { cmd += " WHERE " + string.Join(" AND ", conditions.ToArray()); } DatabaseProvider.ExecuteCommand(cmd); // DatabaseProvider.BeginReader(); while (DatabaseProvider.Reader.Read()) { int id = (int)DatabaseProvider.Reader["id"]; string name = (string)DatabaseProvider.Reader["name"]; string category = (string)DatabaseProvider.Reader["category"]; string price = (string)DatabaseProvider.Reader["Price"]; InternetShop collection = new InternetShop(id, name, category, price); ResultInternetShop.Add(collection); } DatabaseProvider.FinishReader(); // DatabaseProvider.CloseConnection(); return(ResultInternetShop); }
public void Delete(InternetShopFilter filter) { List <InternetShop> currentCollections = Get(new InternetShopFilter()); // gets ALL the Collections, because the filter is empty here FilesProvider.OpenWriter("InternetShop", false); foreach (InternetShop Collection in currentCollections) { if (Collection.Id != filter.Id) { FilesProvider.WriteMusicCollection(Collection); } } FilesProvider.CloseWriter(); }
void updateInternetShop() { IInternetShopRepository InternetShopRepo = factory.GetInternetShopRepository(); menu.CurrentInternetShop(); showInternetShop(new List <InternetShop>(InternetShopRepo.Get(new InternetShopFilter()))); InternetShopFilter filter = new InternetShopFilter(); filter.SetConditions(); menu.EmptyRows(1); InternetShopRepo.Update(filter); menu.InternetShopAfter(); showInternetShop(new List <InternetShop>(InternetShopRepo.Get(new InternetShopFilter()))); }
void deleteFromInternetShop() { IInternetShopRepository InternetShopRepo = factory.GetInternetShopRepository(); menu.CurrentInternetShop(); showInternetShop(new List <InternetShop>(InternetShopRepo.Get(new InternetShopFilter()))); menu.InputInternetShopId(); InternetShopFilter filter = new InternetShopFilter(); filter.Id = Convert.ToInt32(Console.ReadLine()); menu.EmptyRows(1); InternetShopRepo.Delete(filter); menu.InternetShopAfter(); showInternetShop(new List <InternetShop>(InternetShopRepo.Get(new InternetShopFilter()))); }
public List <InternetShop> Get(InternetShopFilter filter) { List <InternetShop> ResultInternetShop = new List <InternetShop>(); FilesProvider.OpenReader("InternetShop"); int peek = FilesProvider.Peek(); while (peek != -1) { string IdRow = FilesProvider.ReadRow(); if (string.IsNullOrEmpty(IdRow)) { break; // means that if file is empty } string[] IdParts = IdRow.Split(':'); int id = Convert.ToInt32(IdParts[1].Trim()); string NameRow = FilesProvider.ReadRow(); string[] NameParts = NameRow.Split(':'); string name = NameParts[1].Trim(); string CategoryRow = FilesProvider.ReadRow(); string[] CategoryParts = NameRow.Split(':'); string category = CategoryParts[1].Trim(); string PriceRow = FilesProvider.ReadRow(); string[] PriceParts = PriceRow.Split(':'); string price = PriceParts[1].Trim(); InternetShop Collection = new InternetShop(id, name, category, price); ResultInternetShop.Add(Collection); peek = FilesProvider.Peek(); if (FilesProvider.ReadRow() == "") { continue; } } // while FilesProvider.CloseReader(); return(ResultInternetShop); }
public void Update(InternetShopFilter filter) { Delete(filter); Add(filter); }