//Добавление продукции в базе для выбраного магазина private void Add(string nameShopr) { List <ModelProductDAO> modelProductDAOs = new List <ModelProductDAO>(); ModelProductDAO modelProductDAO = new ModelProductDAO(); List <ModelDatePrice> listmodelDatePrices = null; ModelDatePrice modelDatePrice = null; var prod = dAOContext.shope.FirstOrDefault(s => s.nameShope == nameShopr); foreach (var product in ManagerShope.listProduct) { modelDatePrice = new ModelDatePrice(); listmodelDatePrices = new List <ModelDatePrice>(); var s = prod.shope.FirstOrDefault(p => p.id == product.id); if (s == null) { modelDatePrice.dataTime = DateTime.Today.ToLongDateString(); modelDatePrice.price = product.price; listmodelDatePrices.Add(modelDatePrice); modelProductDAO.description = product.description; modelProductDAO.listPhoto = DeserizerPhotoInStr(product.listPhoto); modelProductDAO.ModelDatePrice = listmodelDatePrices; modelProductDAO.nameProduct = product.nameProduct; modelProductDAO.id = product.id; dAOContext.shope.Update(prod); dAOContext.SaveChanges(); } } }
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); }
//Возращает колекцию цен с датами продукта private List <ModelDatePrice> GetDatePrices(string price, ModelProductDAO modelProductDAO = null) { List <ModelDatePrice> listModelDatePrices = new List <ModelDatePrice>(); ModelDatePrice modelDatePrice = new ModelDatePrice(); try { if (modelProductDAO != null && modelProductDAO.ModelDatePrice != null) { listModelDatePrices = modelProductDAO.ModelDatePrice; } modelDatePrice.dataTime = DateTime.Today.ToLongDateString(); modelDatePrice.price = price; listModelDatePrices.Add(modelDatePrice); } catch (Exception e) { throw new Exception(e.Message); } return(listModelDatePrices); }
//Удалкеие продукции из базы для выбраного магазина private void Remove(string nameShopr) { List <ModelProductDAO> modelProductDAOs = new List <ModelProductDAO>(); ModelProductDAO modelProductDAO = null; var prod = dAOContext.shope.FirstOrDefault(s => s.nameShope == nameShopr).shope; foreach (var product in prod) { modelProductDAO = new ModelProductDAO(); var s = ManagerShope.listProduct.Find(p => p.id == product.id); if (s == null) { modelProductDAOs.Add(product); } } if (modelProductDAOs.Count != 0) { dAOContext.shopeTb.RemoveRange(modelProductDAOs); dAOContext.SaveChanges(); } }