コード例 #1
0
        public ActionResult Create(TestimonialViewModel viewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var entity = Mapper.Map <TestimonialViewModel, Testimonial>(viewModel);

                    _testimonialService.Insert(entity);

                    viewModel.Locales.ToList().ForEach(l =>
                    {
                        _localizedEntityService.SaveLocalizedValue(entity, e => e.Text, l.Text, l.LanguageId);
                    });

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
            }

            //viewModel.ClientsSelectList = Mapper.Map<List<Client>, List<SelectListItem>>(_clientService.GetAll());
            viewModel.ProjectsSelectList = Mapper.Map <List <Project>, List <SelectListItem> >(_projectService.GetAll());

            return(View(viewModel));
        }