Пример #1
0
        public ActionResult Edit([Bind(Include = "Id, Employee, Month, Department, SubscriptionType, Amount, Notes, IsFixed")] Subscription subscription)
        {
            Db db = new Db(DbServices.ConnectionString);

            if (ModelState.IsValid)
            {
                try
                {
                    SubscriptionServices.Update(CurrentUser.Id, subscription, db);
                    TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "UpdateConfirmed");
                    return(RedirectToAction("Index"));
                }
                catch (CfException cfex)
                {
                    TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage;
                }
                catch (Exception ex)
                {
                    TempData["Failure"] = ex.Message;
                }
            }

            ViewBag.DepartmentList       = new SelectList(DepartmentServices.List(db), "Id", "Name", subscription.Department);
            ViewBag.EmployeeList         = new SelectList(EmployeeServices.List(db), "Id", "FirstName", subscription.Employee);
            ViewBag.SubscriptionTypeList = new SelectList(SubscriptionTypeServices.List(db), "Id", "Name", subscription.SubscriptionType);
            return(View(subscription));
        }
Пример #2
0
        public void TestUpdateMustCallRepository()
        {
            var dataToUpdate = Builder <SubscriptionDTO> .CreateNew().Build();

            dataToUpdate.Name = "NameNew";
            var dataToOld = Builder <SubscriptionModel> .CreateNew().Build();

            dataToOld.Name = "NameOld";

            _subscriptionRepositoryMock.Setup(m => m.GetById(dataToUpdate.Id)).Returns(dataToOld);

            target.Update(dataToUpdate);

            _subscriptionRepositoryMock.Verify(m => m.Update(It.Is <SubscriptionModel>(arg => arg.Name == "NameNew")), Times.Once);
        }