public async Task <ActionResult> Delete(AuthorAphorism model)
        {
            if (await Repo.GetByKeyAsync(model.Id) == null)
            {
                return(new HttpNotFoundResult());
            }

            await Repo.DeleteAsync(model);

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit(VMAuthorAphorism model)
        {
            var isNew = model.Id == 0;

            if (isNew || string.IsNullOrWhiteSpace(model.TitleUrl))
            {
                model.TitleUrl = UrlHelperExtensions.SeoFriendlyUrl(model.Name);
            }

            var existByTitleModel = await Repo.GetByTitleUrlAsync(model.TitleUrl);

            if (existByTitleModel != null)
            {
                if (!Equals(existByTitleModel.Id, model.Id))
                {
                    ModelState.AddModelError("TitleUrl", "Запись с таким строковым ключем уже содержиться в БД");
                }
            }

            var redactModel = Mapper.Map <VMAuthorAphorism, AuthorAphorism>(model);

            if (isNew)
            {
                var exist = await Repo.GetByNameAsync(model.Name);

                if (exist != null)
                {
                    ModelState.AddModelError("Name", "Автор с таким именем уже существует в БД");
                }
            }

            if (ModelState.IsValid)
            {
                AuthorAphorism newModel = null;
                if (isNew)
                {
                    newModel = Repo.Create(redactModel);
                }
                else
                {
                    newModel = Repo.Update(redactModel, true, "Name", "Description", "PictureId", "TitleUrl", "Foreword");
                }

                return(RedirectToAction("index"));
            }
            else
            {
                return(View(model));
            }
        }
        public async Task<ActionResult> Delete(AuthorAphorism model)
        {
            if (await Repo.GetByKeyAsync(model.Id) == null)
                return new HttpNotFoundResult();

            await Repo.DeleteAsync(model);
            return RedirectToAction("Index");
        }