Exemple #1
0
        public static string ReadTextAsJson(string filePath)
        {
            string result = null;

            string[]          lines, splitLine;
            string            subLine;
            List <CoverModel> coverList = new List <CoverModel>();

            //result = File.ReadAllText(filePath);
            lines = File.ReadAllLines(filePath);

            foreach (string line in lines)
            {
                subLine   = line.Length > 40 ? line.Substring(39) : "";
                splitLine = subLine.Split(new char[] { '.', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                int splitCount = 0;
                splitCount = splitLine.Count();
                if (splitCount > 1 && splitLine[--splitCount] == "jpg")
                {
                    CoverModel cover = new CoverModel();
                    cover.Filename = subLine;
                    coverList.Add(cover);
                }
            }
            ParseCoverFilename(coverList);
            result = JsonConvert.SerializeObject(coverList);
            return(result);
        }
Exemple #2
0
        public async Task <ActionResult <CoverModel> > PostCover([FromBody] CoverModel cover)
        {
            //CoverModel cover = new CoverModel { label = "NewCover", filename = "New Cover" };

            doruContext.CoverSet.Add(cover);
            await doruContext.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetCover), new { id = cover.Id }, cover));
        }
        public async Task <IActionResult> PutCover(long id, [FromBody] CoverModel cover)
        {
            if (id != cover.Id)
            {
                return(BadRequest());
            }

            doruDB.Entry(cover).State = EntityState.Modified;
            await doruDB.SaveChangesAsync();

            return(NoContent());
        }
        public async Task <ActionResult <CoverModel> > PostCover([FromBody] CoverModel cover)
        {
            //return coverRepo.AddCover(cover);
            try
            {
                doruDB.Cover.Add(cover);
                await doruDB.SaveChangesAsync();

                return(CreatedAtAction(nameof(GetCover), new { id = cover.Id }, cover));
            }
            catch
            {
                throw;
            }
        }
Exemple #5
0
        public static string ReadTextAsJson(string filePath)
        {
            string result = null;

            string[]          lines, splitStr;
            string            covercast = "", coverseries = "", subLine;
            DateTime          reldate;
            List <CoverModel> coverList = new List <CoverModel>();

            //result = File.ReadAllText(filePath);
            lines = File.ReadAllLines(filePath);
            // convert all lines to small case

            int i = 0, splitCount = 0;

            foreach (string line in lines)
            {
                subLine    = line.Length > 40 ? line.Substring(39) : "";
                splitStr   = subLine.Split(new char[] { '.', ' ' }, StringSplitOptions.None);
                splitCount = splitStr.Count();
                if (splitCount > 1 && splitStr[--splitCount] == "jpg")
                {
                    CoverModel cover = new CoverModel();

                    if (Common.IsStringDateTime(splitStr[--splitCount], out reldate))
                    {
                        cover.releasedate = reldate.ToShortDateString();
                    }
                    covercast = "";
                    for (--splitCount; splitCount > 0; --splitCount)
                    {
                        covercast = $" {splitStr[splitCount]}{covercast}";
                    }
                    cover.cast = covercast.Trim();
                    if (Common.IsStringCoverSeries(splitStr[0], out coverseries))
                    {
                        cover.series = coverseries.Trim();
                    }

                    cover.Id       = ++i;
                    cover.filename = subLine;
                    coverList.Add(cover);
                }
            }
            result = JsonConvert.SerializeObject(coverList);
            return(result);
        }
Exemple #6
0
        public void AddCover(int id, CoverModel cover)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            var book = _bookRepository.GetById(id);

            if (book is null)
            {
                throw new Exception("Book not found");
            }

            book.CoverId = cover.Id;

            _bookRepository.Update(book);

            var coverMap = _mapper.Map <Cover>(cover);

            _coverRepository.Create(coverMap);
        }
Exemple #7
0
        public static HttpResponseMessage RetrieveContentFromCover(this HttpResponseMessage response, CoverModel cover)
        {
            string GetMimeType(string pathToFile)
            {
                new FileExtensionContentTypeProvider().TryGetContentType(pathToFile, out var contentType);
                return(contentType ?? "application/octet-stream");
            }

            StreamContent content = new StreamContent(new FileStream(cover.LinkTo, FileMode.Open));

            response.Content = content;
            response.Content.Headers.ContentType = new MediaTypeHeaderValue(GetMimeType(cover.LinkTo));
            response.StatusCode = HttpStatusCode.OK;

            return(response);
        }