Exemplo n.º 1
0
        public bool Update(EditStockVm editStockVm, Stock stock)
        {
            if (editStockVm.Id == stock.Id)
            {
                stock.Symbol = editStockVm.Symbol;
                stock.Title = editStockVm.Title;

                return StockRepository.UpdateStock(stock).OperationSuccessStatus;
            }

            return false;
        }
Exemplo n.º 2
0
        //
        // GET: /Stocks/Edit/5
        public ActionResult Edit(int id)
        {
            var stock = StockService.GetStock(id);
            if (stock == null)
            {
                this.FlashError("Invalid stock requested. Please try again.", "Index", "Stocks");
                return RedirectToAction("Index", "Stocks", new { area = "" });
            }

            ViewBag.Stock = stock;

            var editStockVm = new EditStockVm
            {
                Title = stock.Title,
                Symbol = stock.Symbol,
                Id = stock.Id
            };

            return View(editStockVm);
        }
Exemplo n.º 3
0
        public ActionResult Edit(int id, EditStockVm editStockVm)
        {
            var stock = StockService.GetStock(id);
            if (stock == null)
            {
                this.FlashError("Invalid stock requested. Please try again.", "Index", "Stocks");
                return RedirectToAction("Index", "Stocks", new { area = "" });
            }

            if (ModelState.IsValid)
            {
                bool symbolDiff = stock.Symbol != editStockVm.Symbol;
                if (!symbolDiff ||
                    (!StockService.ValidateDuplicateSymbol(editStockVm.Symbol)))
                {
                    bool updatedStock = StockService.Update(editStockVm, stock);

                    if (updatedStock)
                    {
                        this.FlashSuccess("Successfully updated the stock.", "Details", "Stocks");
                        return RedirectToAction("Details", "Stocks", new { area = "", id = stock.Id });
                    }
                    this.FlashError("Could not update the stock. Please try again.", "Edit", "Stocks");
                }
                else
                {
                    ModelState.AddModelError("Symbol", "The provided symbol already exists.");
                    this.FlashError("The provided symbol already exists.", "Edit", "Stocks");
                }

            }

            return View(editStockVm);
        }