예제 #1
0
        public async Task CreateAlbumSRVC(CreateAlbumServiceModel model)
        {
            var album = new Album
            {
                AuthorId = model.AuthorId,
                Title    = model.Title
            };

            await this.db.Albums.AddAsync(album);

            await this.db.SaveChangesAsync();
        }
예제 #2
0
        public async Task AddPhotoSRVC(CreateAlbumServiceModel model)
        {
            var album = this.db.Albums.Find(model.Id);
            var photo = new Photo
            {
                Name = model.PhotoName,
                Url  = model.PhotoUrl
            };

            var res = this.db.Albums.Where(i => i.Id == model.Id).SingleOrDefault();

            res.Photos.Add(photo);
            await this.db.SaveChangesAsync();
        }
예제 #3
0
        public async Task <IActionResult> AddPhotos(CreateAlbumServiceModel model)
        {
            if (!ModelState.IsValid)
            {
                TempData.AddErrorMessage(ErrorModelState());
                return(View(model));
            }
            if (!User.IsInRole(AuthorRole))
            {
                return(RedirectToAction(HomeIndex));
            }
            await this.albumService.AddPhotoSRVC(model);

            TempData.AddSuccessMessage(SuccessAddPhoto);

            return(RedirectToAction(IndexAction, GalleryControllerConst, new { area = AreaGallery }));
        }
예제 #4
0
        public async Task <IActionResult> CreateAlbum(CreateAlbumServiceModel model)
        {
            model.AuthorId = this.userManager.GetUserId(User);


            if (!User.IsInRole(AuthorRole))
            {
                RedirectToAction(HomeIndex);
            }
            if (!ModelState.IsValid)
            {
                TempData.AddErrorMessage(ErrorModelState());
                return(View(model));
            }
            await this.albumService.CreateAlbumSRVC(model);

            return(RedirectToAction(IndexAction));
        }