Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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");
        }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
        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;
        }