public ActionResult Create(SermonMetaDataCreateViewModel sermonMetaDataCreateViewModel) { if (ModelState.IsValid) { SermonData newSermonData = new SermonData(); newSermonData.SermonDataID = Guid.NewGuid(); newSermonData.Active = true; //newSermonData.SermonDataDataTypesID = 1; sermonMetaDataCreateViewModel.SermonMetaData.SermonDatas.Add(newSermonData); int[] selectedCategories = sermonMetaDataCreateViewModel.SermonCategoryies.Where(x => x.Selected).Select<SelectListItem, int>(x => Convert.ToInt32(x.Value.ToString())).ToArray<int>(); sermonMetaDataCreateViewModel.SermonMetaData.SermonCategories.Clear(); sermonMetaDataCreateViewModel.SermonMetaData.SermonCategories = unitOfWork.SermonCategoryRepository.Get(x => selectedCategories.Contains(x.SermonCategoryID)).ToList(); unitOfWork.SermonMetaDataRepository.Insert(sermonMetaDataCreateViewModel.SermonMetaData); unitOfWork.Save(); foreach (var sermonMetaData in sermonMetaDataCreateViewModel.SermonMetaData.SermonDatas) { var path = Path.Combine(unitOfWork.SermonConfigRepository.SermonDataPath, Path.GetFileName(sermonMetaData.SermonDataID.ToString("D").ToUpperInvariant() + Path.GetExtension(sermonMetaDataCreateViewModel.SermonAudioFile.FileName))); sermonMetaDataCreateViewModel.SermonAudioFile.SaveAs(path); } return RedirectToAction("Index"); } //sermonMetaDataCreateViewModel.SermonMetaData = SermonMetaDataSetupBase(sermonMetaDataCreateViewModel.SermonMetaData); sermonMetaDataCreateViewModel = SermonMetaDataBaseInitialize(sermonMetaDataCreateViewModel.SermonMetaData).ToCreateViewModel(); return View(sermonMetaDataCreateViewModel); }
public SermonMetaDataCreateViewModel ToCreateViewModel() { SermonMetaDataCreateViewModel CVM = new SermonMetaDataCreateViewModel(); CVM.SermonMetaData = this.SermonMetaData; CVM.SermonAudioFile = this.SermonAudioFile; CVM.SermonCategoryies = this.SermonCategoryies; return CVM; }