public void DeletePrice(List <string> lstSymbole) { try { using (var unitOfWork = new EFUnitOfWork()) { var priceRepo = new PriceRepository(new EFRepository <Price>(), unitOfWork); ObjectSet <Price> priceObj = ((CurrentDeskClientsEntities)priceRepo.Repository.UnitOfWork.Context).Prices; var lstPrice = priceObj.Where(p => lstSymbole.Contains(p.Symbole)).ToList(); foreach (var price in lstPrice) { priceRepo.Delete(price); } priceRepo.Save(); } } catch (Exception ex) { CommonErrorLogger.CommonErrorLog(ex, System.Reflection.MethodBase.GetCurrentMethod().Name); } }
// Add your own data access methods here. If you wish to // expose your public method to a WCF service, marked them with // the attribute [NCPublish], and another T4 template will generate your service contract public void DeleteSymbol(string symbole) { try { using (var unitOfWork = new EFUnitOfWork()) { var priceRepo = new PriceRepository(new EFRepository <Price>(), unitOfWork); ObjectSet <Price> priceObj = ((CurrentDeskClientsEntities)priceRepo.Repository.UnitOfWork.Context).Prices; var price = priceObj.Where(s => s.Symbole == symbole).FirstOrDefault(); if (price != null) { priceRepo.Delete(price); priceRepo.Save(); } } } catch (Exception ex) { CommonErrorLogger.CommonErrorLog(ex, System.Reflection.MethodBase.GetCurrentMethod().Name); } }
public void InsertPrice(List <Price> lstPrice) { try { using (var unitOfWork = new EFUnitOfWork()) { var priceRepo = new PriceRepository(new EFRepository <Price>(), unitOfWork); ObjectSet <Price> priceObj = ((CurrentDeskClientsEntities)priceRepo.Repository.UnitOfWork.Context).Prices; var lstSymbole = lstPrice.Select(s => s.Symbole).ToList(); //Get the existing price from DB and update with New DB var lstDBPrice = priceObj.Where(p => lstSymbole.Contains(p.Symbole)).ToList(); foreach (var uPrice in lstDBPrice) { var newPrice = lstPrice.Where(s => s.Symbole == uPrice.Symbole.Trim()).FirstOrDefault(); if (newPrice != null) { uPrice.Ask = newPrice.Ask; uPrice.Bid = newPrice.Bid; } } //Add new price var lstDBPriceSymbole = lstDBPrice.Select(p => p.Symbole.Trim()).ToList(); var newPricesToAdd = lstPrice.Where(lp => !lstDBPriceSymbole.Contains(lp.Symbole)).Distinct().ToList(); foreach (var price in newPricesToAdd) { priceRepo.Add(price); } priceRepo.Save(); } } catch (Exception ex) { CommonErrorLogger.CommonErrorLog(ex, System.Reflection.MethodBase.GetCurrentMethod().Name); } }