public string Edit(EditStockOfClientInfo editArgs) { int entityId; string result = String.Empty; var entityToEdit = new StockOfClientsEntity() { ClientID = editArgs.Client_ID, StockID = editArgs.Stock_ID, Amount = editArgs.AmountOfStocks }; if (this.stockOfClientsTableRepository.Contains(entityToEdit, out entityId)) { result = this.stockOfClientsTableRepository.Update(entityId, entityToEdit); } else { this.stockOfClientsTableRepository.Add(entityToEdit); result = $"Entry for client {entityToEdit.ClientID} was added into DB"; //throw new ArgumentException("There is no entry in DataBase, may be you eentered wrong userID or stockID"); } this.stockOfClientsTableRepository.SaveChanges(); return(result); }
public string Update(int entityId, StockOfClientsEntity newEntity) { var stockOfCloentToUpdate = this.dbContext.StockOfClients.FirstOrDefault(c => c.ID == entityId); if (stockOfCloentToUpdate != null) { stockOfCloentToUpdate.Amount = newEntity.Amount; SaveChanges(); return("Stock of Client data was updated."); } return("Stock of Client data wasn't found."); }
public string Remove(int entityId, StockOfClientsEntity entityToRemove) { var stockOfClientToRemove = this.dbContext.StockOfClients.FirstOrDefault(c => c.ID == entityId); if (stockOfClientToRemove != null) { this.dbContext.StockOfClients.Remove(stockOfClientToRemove); this.dbContext.SaveChanges(); return("Stock of Client was deleted."); } return("Stock of Client wasn't found."); }
public bool Contains(StockOfClientsEntity entityToCheck, out int entityId) { var entry = this.dbContext.StockOfClients .FirstOrDefault(sc => sc.ClientID == entityToCheck.ClientID && sc.StockID == entityToCheck.StockID); if (entry != null) { entityId = entry.ID; return(true); } entityId = 0; return(false); }
public string Remove(EditStockOfClientInfo removeInfo) { int entityId; string result = String.Empty; var entityToRemove = new StockOfClientsEntity() { ClientID = removeInfo.Client_ID, StockID = removeInfo.Stock_ID }; if (this.stockOfClientsTableRepository.Contains(entityToRemove, out entityId)) { result = this.stockOfClientsTableRepository.Remove(entityId, entityToRemove); return(result); } throw new ArgumentException($"Entry to remove with such clientID {removeInfo.Client_ID} and StockID {removeInfo.Stock_ID} wasn't found"); }
public string addStock(EditStockOfClientInfo addInfo) { int entityId; var entityToAdd = new StockOfClientsEntity() { ClientID = addInfo.Client_ID, StockID = addInfo.Stock_ID, Amount = addInfo.AmountOfStocks }; if (this.stockOfClientsTableRepository.Contains(entityToAdd, out entityId)) { throw new ArgumentException("This client has already owned this stock, please use update request or select anothers parameters."); } this.stockOfClientsTableRepository.Add(entityToAdd); this.stockOfClientsTableRepository.SaveChanges(); stockOfClientsTableRepository.Contains(entityToAdd, out entityId); return(entityId.ToString()); }
/// <summary> /// Adds StockOfClientsEntity into database. /// </summary> /// <param name="entity">Entity toa dd.</param> public void Add(StockOfClientsEntity entity) { this.DbContext.StockOfClients.Add(entity); }
public void Update(int entityId, StockOfClientsEntity newEntity) { var entityToUpdate = this.dbContext.StockOfClients.First(sc => sc.ID == entityId); entityToUpdate = newEntity; }