public int Create(AddStockVm addStockVm) { var stock = new Stock { Title = addStockVm.Title, Symbol = addStockVm.Symbol, }; DbOperationStatus opStatus = StockRepository.InsertStock(stock); if (opStatus.OperationSuccessStatus) { return(opStatus.AffectedIndices.First()); } return(-1); }
public ActionResult Add(AddStockVm addStockVm) { if (ModelState.IsValid) { if (!StockService.ValidateDuplicateSymbol(addStockVm.Symbol)) { int stockId = StockService.Create(addStockVm); if (stockId > 0) { this.FlashSuccess("Successfully created the stock.", "Details", "Stocks"); return(RedirectToAction("Details", "Stocks", new { area = "", id = stockId })); } this.FlashError("Could not create the stock. Please try again.", "Add", "Stocks"); } else { ModelState.AddModelError("Symbol", "The provided stock already exists."); this.FlashError("The provided stock already exists.", "Add", "Stocks"); } } return(View(addStockVm)); }