public void CreateSliderElement(SliderLang model, string mapPath) { using (var db = new DataContext()) { var slider = new Slider() { CreateDate = (model.CreateDate != null) ? model.CreateDate : DateTime.Now }; db.Sliders.Add(slider); var sliderLangRu = new SliderLanguage() { SliderId = slider.Id, LanguageId = EnumLanguage.ru, Title = model.Ru_Title, Content = model.Ru_Content }; db.SliderLanguages.Add(sliderLangRu); var sliderLangRo = new SliderLanguage() { SliderId = slider.Id, LanguageId = EnumLanguage.ro, Title = model.Ro_Title, Content = model.Ro_Content }; db.SliderLanguages.Add(sliderLangRo); if (model.PhotoFile != null) { slider.Photo = UploadModuleImage(model.PhotoFile, mapPath, slider.Id); } db.SaveChanges(); } }
public static ModelSlider ConvertToModelSlider(SliderLanguage model) { return(new ModelSlider() { Id = model.SliderId, CreateDate = model.Slider.CreateDate, Photo = model.Slider.Photo, Title = model.Title, Content = model.Content }); }