private ModelAllShoppe SetModelAllShope() { ModelAllShoppe modelAllShoppe = null; ModelProductDAO modelProduct = null; ModelPhoto modelPhoto = null; ModelDatePrice modelDate = null; modelAllShoppe = new ModelAllShoppe(); modelAllShoppe.shope = new List <ModelProductDAO>(); foreach (var product in ManagerShope.listProduct) { modelProduct = new ModelProductDAO(); modelPhoto = new ModelPhoto(); modelDate = new ModelDatePrice(); modelProduct.listPhoto = new List <ModelPhoto>(); modelProduct.ModelDatePrice = new List <ModelDatePrice>(); modelDate.dataTime = DateTime.Today.ToLongDateString(); modelDate.price = product.price; modelProduct.listPhoto.AddRange(DeserizerPhotoInStr(product.listPhoto)); modelProduct.ModelDatePrice.Add(modelDate); modelProduct.description = product.description; modelProduct.id = product.id; modelProduct.nameProduct = product.nameProduct; modelAllShoppe.shope.Add(modelProduct); } return(modelAllShoppe); }
//Проверка на существование имени и продуктов магазина public bool CheckNameShopeInDb(string nameShope) { bool isShopeDB = default; init(); try { if (nameShope == null) { throw new ArgumentNullException("Object reference is not specified"); } ModelAllShoppe modelAllShoppe = dAOContext.shope.FirstOrDefault(sh => sh.nameShope == nameShope); if (modelAllShoppe != null) { isShopeDB = true; } else { isShopeDB = false; } } catch (ArgumentNullException e) { throw new ArgumentNullException(e.Message); } catch (Exception e) { throw new Exception(e.Message); } return(isShopeDB); }
//Чтение всех продуктов из базы для выбрпного магазина public List <ModelProductDAO> GetAllProduct(string nameShope, bool isShopeDB) { init(); ModelAllShoppe listCurentShope = null; try { if (nameShope == null) { throw new ArgumentNullException("Object reference is not specified"); } listCurentShope = dAOContext.shope.FirstOrDefault(s => s.nameShope == nameShope); if (listCurentShope == null) { throw new ArgumentNullException("Object reference is not specified"); } if (isShopeDB) { string price = null; string nameProduct = null; string description = null; List <string> listPhoto = null; string id = null; Product product = null; string tempDate = DateTime.Today.ToLongDateString(); foreach (var prod in listCurentShope.shope) { listPhoto = new List <string>(); price = prod.ModelDatePrice.Last().price; nameProduct = prod.nameProduct; description = prod.description; id = prod.id; foreach (var photo in prod.listPhoto) { listPhoto.Add(photo.photo); } product = new Product(price, description, listPhoto, nameProduct, id); product.dataTime = prod.ModelDatePrice; ManagerShope.listProduct.Add(product); } return(null); } } catch (ArgumentNullException e) { throw new ArgumentNullException(e.Message); } catch (Exception e) { throw new Exception(e.Message); } return(listCurentShope.shope); }
//Добавление всех даных в базу для нового магазина public async Task AddAllProductInDB(string nameShope) { init(); ModelAllShoppe modelAllShoppe = SetModelAllShope(); modelAllShoppe.nameShope = nameShope; await dAOContext.shope.AddAsync(modelAllShoppe); await dAOContext.SaveChangesAsync(); }