Ejemplo n.º 1
0
        public ActionResult Create(VacancyViewModel viewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var vacancy = Mapper.Map <VacancyViewModel, Vacancy>(viewModel);

                    vacancy.Technologies = viewModel.TechnologiesIds != null?
                                           _technologyService.GetByIds(viewModel.TechnologiesIds) : new List <Technology>();

                    _vacancyService.Insert(vacancy);

                    viewModel.Locales.ToList().ForEach(l =>
                    {
                        _localizedEntityService.SaveLocalizedValue(vacancy, e => e.Title, l.Title, l.LanguageId);
                        _localizedEntityService.SaveLocalizedValue(vacancy, e => e.ShortDescription, l.ShortDescription, l.LanguageId);
                        _localizedEntityService.SaveLocalizedValue(vacancy, e => e.Bonuses, l.Bonuses, l.LanguageId);
                        _localizedEntityService.SaveLocalizedValue(vacancy, e => e.Requirments, l.Requirments, l.LanguageId);
                        _localizedEntityService.SaveLocalizedValue(vacancy, e => e.Responsibilities, l.Responsibilities, l.LanguageId);
                        _localizedEntityService.SaveLocalizedValue(vacancy, e => e.WeOffer, l.WeOffer, l.LanguageId);
                    });

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
                viewModel.TechnologiesSelectList = Mapper.Map <List <Technology>, List <SelectListItem> >(_technologyService.GetAll());
            }


            return(View(viewModel));
        }
Ejemplo n.º 2
0
        public ActionResult Create(ProjectViewModel viewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var project = Mapper.Map <ProjectViewModel, Project>(viewModel);

                    project.Technologies = viewModel.TechnologiesIds != null?
                                           _technologyService.GetByIds(viewModel.TechnologiesIds) : new List <Technology>();

                    project.Services = viewModel.ServicesIds != null?
                                       _serviceService.GetByIds(viewModel.ServicesIds) : new List <Service>();

                    project.Contributors = viewModel.ContributorsIds != null?
                                           _userService.GetByIds(viewModel.ContributorsIds) : new List <User>();

                    _projectService.Insert(project);

                    viewModel.Locales.ToList().ForEach(l =>
                    {
                        _localizedEntityService.SaveLocalizedValue(project, e => e.Title, l.Title, l.LanguageId);
                        _localizedEntityService.SaveLocalizedValue(project, e => e.Kewywords, l.Kewywords, l.LanguageId);
                        _localizedEntityService.SaveLocalizedValue(project, e => e.Overview, l.Overview, l.LanguageId);
                        _localizedEntityService.SaveLocalizedValue(project, e => e.Objective, l.Objective, l.LanguageId);
                        _localizedEntityService.SaveLocalizedValue(project, e => e.WorkOverview, l.WorkOverview, l.LanguageId);
                        _localizedEntityService.SaveLocalizedValue(project, e => e.ResultOverview, l.ResultOverview, l.LanguageId);
                    });

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
                viewModel.ClientsSelectList      = Mapper.Map <List <Client>, List <SelectListItem> >(_clientService.GetAll());
                viewModel.TechnologiesSelectList = Mapper.Map <List <Technology>, List <SelectListItem> >(_technologyService.GetAll());
                viewModel.ContributorsSelectList = Mapper.Map <List <User>, List <SelectListItem> >(_userService.GetAll());
                viewModel.ServicesSelectList     = Mapper.Map <List <Service>, List <SelectListItem> >(_serviceService.GetAll());
            }

            viewModel.ClientsSelectList      = Mapper.Map <List <Client>, List <SelectListItem> >(_clientService.GetAll());
            viewModel.TechnologiesSelectList = Mapper.Map <List <Technology>, List <SelectListItem> >(_technologyService.GetAll());
            viewModel.ContributorsSelectList = Mapper.Map <List <User>, List <SelectListItem> >(_userService.GetAll());
            viewModel.ServicesSelectList     = Mapper.Map <List <Service>, List <SelectListItem> >(_serviceService.GetAll());

            return(View(viewModel));
        }
Ejemplo n.º 3
0
        public ActionResult Edit(UserViewModel viewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var user = Mapper.Map <UserViewModel, User>(viewModel);

                    user.Technologies = viewModel.TechnologiesIds != null?
                                        _technologyService.GetByIds(viewModel.TechnologiesIds) :
                                            new List <Technology>();

                    viewModel.Locales.ToList().ForEach(l =>
                    {
                        _localizedEntityService.SaveLocalizedValue(user, e => e.Title, l.Title, l.LanguageId);
                        _localizedEntityService.SaveLocalizedValue(user, e => e.UserName, l.UserName, l.LanguageId);
                        _localizedEntityService.SaveLocalizedValue(user, e => e.Biography, l.Biography, l.LanguageId);
                    });

                    _userService.Update(user);
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);

                return(View(viewModel));
            }

            return(RedirectToAction("Index"));
        }