private PersonViewModel GetVeteran(int personId) { var person = Db.Get<Veteran>(personId); var model = new PersonViewModel(); if (person != null) { model = Mapper.Map(person, model); } return model; }
public ActionResult Index(int id) { var model = new PersonViewModel(); var item = Db.Get<Veteran>(id); if (item == null) { return View("ServerError", (object)"Страница не найдена"); } model = Mapper.Map(item, model); return View(model); }
public ActionResult AddOrEdit(int? id) { var model = new PersonViewModel(); if (id.HasValue) { var item = Db.Get<Veteran>(id.Value); model = Mapper.Map(item, model); model.Docs.AddRange( item.Albums.Select(a => new CarouselViewModel(a.Path, Server.MapPath(a.Path), a.Name, ""))); model.Albums.AddRange( item.Albums.Select(a => new AlbumViewModel { Id = a.Id, Path = a.Path, Name = a.Name})); } return View(model); }
public ActionResult AddOrEdit(PersonViewModel model) { var item = new Person(); if (model.PersonId > 0) { item = Db.Get<Person>((object)model.PersonId); } item = Mapper.Map(model, item); var result = Db.SaveOrUpdate(item); var path = Path.Combine(Server.MapPath($"~/{"Content/images/people"}/{result}")); var directoryInfo = new DirectoryInfo(path); directoryInfo.Create(); return RedirectToAction("List"); }
private PersonViewModel GetPerson(int personId) { var person = Db.Get<Person>((object)personId); PersonViewModel model = new PersonViewModel(); if (person != null) { model = Mapper.Map(person, model); model.Docs.AddRange( person.Albums.Select(a => new CarouselViewModel(a.Path, Server.MapPath(a.Path), a.Name, ""))); model.Files = GetFiles(model); } if (personId == 24) model.Videos = new List<VideoViewModel> { new VideoViewModel { Width = "420", Height = "315", Source = "https://www.youtube.com/embed/c_obyoeuPGo" }, new VideoViewModel { Width = "420", Height = "315", Source = "https://www.youtube.com/embed/CqI7FuD_ytc" } }; return model; }
private IEnumerable<string> GetFiles(PersonViewModel model) { IEnumerable<string> files = new List<string>(); try { var directory = new DirectoryInfo(Server.MapPath(model.FilesFolder)); files = directory.GetFiles().Select(f => f.Name); } catch (Exception ex) { } return files; }