예제 #1
0
        public bool Update(EditMutualFundVm editMutualFundVm, MutualFund mutualFund)
        {
            if (editMutualFundVm.Id == mutualFund.Id)
            {
                mutualFund.Symbol = editMutualFundVm.Symbol;
                mutualFund.Title = editMutualFundVm.Title;

                return MutualRepository.UpdateMutualFund(mutualFund).OperationSuccessStatus;
            }

            return false;
        }
        //
        // GET: /MutualFunds/Edit/5
        public ActionResult Edit(int id)
        {
            var mutualFund = MutualFundService.GetMutualFund(id);
            if (mutualFund == null)
            {
                this.FlashError("Invalid mutual fund requested. Please try again.", "Index", "MutualFunds");
                return RedirectToAction("Index", "MutualFunds", new { area = "" });
            }

            ViewBag.MutualFund = mutualFund;

            var editMutualFundVm = new EditMutualFundVm
            {
                Title = mutualFund.Title,
                Symbol = mutualFund.Symbol,
                Id = mutualFund.Id
            };

            return View(editMutualFundVm);
        }
        public ActionResult Edit(int id, EditMutualFundVm editMutualFundVm)
        {
            var mutualFund = MutualFundService.GetMutualFund(id);
            if (mutualFund == null)
            {
                this.FlashError("Invalid mutual fund requested. Please try again.", "Index", "MutualFunds");
                return RedirectToAction("Index", "MutualFunds", new { area = "" });
            }

            if (ModelState.IsValid)
            {
                bool symbolDiff = mutualFund.Symbol != editMutualFundVm.Symbol;
                if (!symbolDiff ||
                    (!MutualFundService.ValidateDuplicateSymbol(editMutualFundVm.Symbol)))
                {
                    bool updatedStock = MutualFundService.Update(editMutualFundVm, mutualFund);

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

            }

            return View(editMutualFundVm);
        }