Esempio n. 1
0
        public async Task <int> AddMemeAsync(AddMemeBindingModel model)
        {
            var checkForDuplicate = this.DbContext
                                    .Memes
                                    .FirstOrDefault(x => x.Title == model.Title);

            if (checkForDuplicate != null)
            {
                return(ErrorId);
            }

            var meme = this.Mapper.Map <Meme>(model);

            meme.Title    = Html_String_Utility.EncodeThisPropertyForMe(meme.Title);
            meme.PhotoURL = Html_String_Utility.EncodeThisPropertyForMe(meme.PhotoURL);

            await this.DbContext.Memes.AddAsync(meme);

            await this.DbContext.SaveChangesAsync();

            return(meme.Id);
        }
Esempio n. 2
0
        public async Task <IActionResult> AddMeme(AddMemeBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                SetErrorMessage(CommonConstants.DangerMessage);

                return(this.AddMeme());
            }

            int generatedId = await this.memeService.AddMemeAsync(model);

            if (generatedId < 1)
            {
                SetErrorMessage(CommonConstants.DuplicateMessage);

                return(this.AddMeme());
            }

            SetSuccessMessage(string.Format(CommonConstants.SuccessMessage, CommonConstants.MemeSuffix));

            return(Redirect(string.Format(RedirectConstants.AdministratorAreaMemeDetailsPage, generatedId)));
        }