Пример #1
0
        public async Task <IActionResult> Add(TitleModel titleModel, string type)
        {
            if (ModelState.IsValid)
            {
                if ((await _titleManager.GetAll()).Any(entity => entity.Name == titleModel.Name))
                {
                    return(Json(new
                    {
                        success = false,
                        messages = new[] { ValidationMessages.TitleNameAlreadyExist }
                    }));
                }

                await using var coverStream = titleModel.Cover?.OpenReadStream();

                if (await _titleArchiver.AddTitle(Mapper.MapToEntity(titleModel, type), titleModel.Tags?.Split(","), coverStream))
                {
                    TempData["SuccessMessage"] = new[] { OtherMessages.TitleAddedSuccessfully };

                    return(Json(new
                    {
                        success = true,
                        destination = Url.Action("Index")
                    }));
                }

                ModelState.AddModelError("SomethingWrong", OtherMessages.SomethingWrong);
            }

            return(Json(new
            {
                success = false,
                messages = ModelState.SelectMany(state => state.Value.Errors).Select(error => error.ErrorMessage)
            }));
        }
Пример #2
0
        public async Task <IActionResult> Titles()
        {
            var titles = new List <object>();

            foreach (var title in (await _titlesManager.GetAll(false)).ToArray())
            {
                titles.Add(new
                {
                    title.Id,
                    title.Name,
                    Type = title.GetType().Name,
                    title.Author,
                    title.Artist,
                    title.Status,
                    title.Nsfw,
                    CoverUrl  = $"/content/{title.Id}/cover.png",
                    UpdatedAt = (await _chapterManager.GetLatestChapter(title, false))?.ReleaseDate
                });
            }

            return(Json(titles));
        }
Пример #3
0
 public async Task <IActionResult> Titles() => View((await _titlesManager.GetAll(_signInManager.IsSignedIn(User))).OrderBy(title => title.Status).ThenBy(title => title.Name));