private async Task <CreateItemViewModel> getCreateItemViewModel(string categoryslug, string titleStr = null) { var user = await _userEngine.CurrentUser(_userManager.GetUserId(User)); var questions = _projectEngine.GetCategoryQuestions(categoryslug); StringValues title; StringValues description; StringValues provinceId; StringValues districtId; StringValues whenTypeId; StringValues whenDateId; StringValues whenTimeId; StringValues price; if (HttpContext.Request.HasFormContentType) { title = HttpContext.Request.Form["Title"]; description = HttpContext.Request.Form["Description"]; provinceId = HttpContext.Request.Form["ProvinceId"]; districtId = HttpContext.Request.Form["DistrictId"]; whenTypeId = HttpContext.Request.Form["WhenTypeId"]; whenDateId = HttpContext.Request.Form["WhenDateId"]; whenTimeId = HttpContext.Request.Form["WhenTimeId"]; price = HttpContext.Request.Form["Price"]; foreach (var question in questions) { question.Value = HttpContext.Request.Form[Converter.String.ToValidControlId(question.Label)]; } } var model = new CreateItemViewModel() { Title = !string.IsNullOrWhiteSpace(titleStr) ? titleStr : title.ToString(), Description = description, SelectedCategory = categoryslug, Categories = _projectEngine.GetUserCategories(true), Questions = questions, Provinces = _projectEngine.GetProvincesSelectList(), ProvinceId = provinceId == string.Empty ? TryParse(provinceId) : (user.ProvinceId.HasValue ? user.ProvinceId.Value : 0), Districts = _projectEngine.GetDistrictsSelectList(provinceId == string.Empty || provinceId.Count == 0 ? user.ProvinceId : TryParse(provinceId)), //DistrictId = districtId == string.Empty ? TryParse(districtId) : (user.DistrictId.HasValue ? user.DistrictId.Value : 0), DistrictId = districtId == string.Empty ? TryParse(districtId) : 0, WhenTypes = _projectEngine.GetWhenTypes(), WhenTypeId = whenTypeId == string.Empty ? TryParse(whenTypeId) : 0, WhenDates = _projectEngine.GetWhenDates(), WhenDateId = whenDateId, WhenTimes = _projectEngine.GetWhenTimes(), WhenTimeId = whenTimeId }; decimal decimalPrice = 0; decimal?PriceValue = null; if (decimal.TryParse(price, out decimalPrice)) { PriceValue = decimalPrice; } model.Price = PriceValue; return(model); }