public ActionResult TaskForm(bool IsExisting, int Id = 0) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <TaskFull, TaskFullViewModel>().ForMember(dest => dest.Category, opt => opt.MapFrom(src => src.Category.Id)).ForMember(dest => dest.Status, opt => opt.MapFrom(src => src.Status.Id)).ForMember(dest => dest.Rank, opt => opt.MapFrom(src => src.Rank.Id)); }); IMapper mapper = config.CreateMapper(); var Viewmodel = new TaskFormViewModel() { RankList = _staticDataRepository.GetRanksDropdown(), CategoryList = _staticDataRepository.GetCategoriesDropdown(_usersRepository.GetCurrentUserId()), StatusList = _staticDataRepository.GetStatusesDropdown(), Task = new TaskFullViewModel() { Id = 0, Progres = 0 } }; if (IsExisting) { Viewmodel.Task = mapper.Map <TaskFull, TaskFullViewModel>(_tasksRepository.Get(Id, _usersRepository.GetCurrentUserId())); ViewBag.Title = "Edit task"; Viewmodel.IsExisting = true; } else { ViewBag.Title = "Add new task"; Viewmodel.IsExisting = false; } return(View(Viewmodel)); }