예제 #1
0
        public ActionResult Edit(ApplicationManageViewModel model)
        {
            if (ModelState.IsValid)
            {
                var application = applicationRepository.GetById(model.Id);
                if (application == null)
                {
                    throw new ArgumentException(string.Format("Application with Id [{0}] does not exist", model.Id));
                }

                try
                {
                    model.ToDalEntity(application);
                    applicationRepository.UpdateAndSubmit(application);

                    base.SetSuccessMessage("The application [{0}] has been updated.", application.Name);
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    base.SetErrorMessage("Whoops! Couldn't update the application. The error was [{0}]", ex.Message);
                }
            }

            LoadTeamsInViewData();
            return(View(model));
        }
예제 #2
0
        public void ToDalEntity_converts_model_properties_to_DAL_entity()
        {
            // setup
            var application = new ApplicationBuilder().WithName("Name").WithDefaultTeam().Build();
            var model       = new ApplicationManageViewModel(application);

            // act
            var result = model.ToDalEntity();

            // verify
            Assert.AreEqual(application.Id, result.Id);
            Assert.AreEqual(application.Name, result.Name);
            Assert.AreEqual(application.Description, result.Description);
            Assert.AreEqual(application.TeamId, result.TeamId);
        }
예제 #3
0
        public ActionResult Create(ApplicationManageViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var application = model.ToDalEntity();
                    applicationRepository.InsertAndSubmit(application);

                    base.SetSuccessMessage("The application [{0}] has been created.", application.Name);
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    base.SetErrorMessage("Whoops! Couldn't create the new application. The error was [{0}]", ex.Message);
                }
            }

            LoadTeamsInViewData();
            return(View(model));
        }