Ejemplo n.º 1
0
        public async Task <IActionResult> Create(GalleryFormModel model)
        {
            if (model.Files == null || model.Files.Count == 0)
            {
                return(Content(NoSelectedFiles));
            }

            var imgPaths = new List <string>();

            foreach (var file in model.Files)
            {
                var path          = Path.Combine(ImageFolderName, GalleriesImageFolderName, Guid.NewGuid() + file.GetFileType());
                var pathForUpload = Path.Combine(Directory.GetCurrentDirectory(), RootFolderName, path);

                using (var stream = new FileStream(pathForUpload, FileMode.Create))
                {
                    await file.CopyToAsync(stream);
                }

                path = path.Replace("\\", "/");
                imgPaths.Add(string.Format(SavePath, path));
            }

            await this.galleries.CreateAsync(
                model.Title,
                imgPaths,
                model.Language
                );

            this.TempData.AddSuccessMessage(string.Format(TempDataCreateCommentText, ModelName, EndingLetterA));

            return(this.RedirectToAction(nameof(this.Galleries)));
        }
        public ActionResult Create(GalleryFormModel model)
        {
            var item = Mapper.Map <GalleryFormModel, Gallery>(model);

            GetSession.Save(item);

            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(GalleryFormModel model)
        {
            var item = GetSession.Get <Gallery>(model.Id);

            Mapper.Map <GalleryFormModel, Gallery>(model, item);
            GetSession.Update(item);

            return(RedirectToAction("Index"));
        }
        public ActionResult Create()
        {
            var model = new GalleryFormModel()
            {
                Id   = Guid.NewGuid(),
                Date = DateTime.Now
            };

            return(View(model));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, GalleryFormModel model)
        {
            await this.galleries.EditAsync(
                id,
                model.Title,
                model.Language,
                model.Show
                );

            this.TempData.AddSuccessMessage(string.Format(TempDataEditCommentText, ModelName, EndingLetterA));

            return(this.RedirectToAction(nameof(this.Galleries)));
        }