Ejemplo n.º 1
0
        public Result GetStudyBook([FromBody] StudyBook book)
        {
            var result = new Result();

            try
            {
                using (var dblocal = new LiteDatabase(db))
                {
                    //get docs, tags and reviews
                    var docsTable        = dblocal.GetCollection <Doc>("Docs").FindAll().ToList();
                    var docsTagsTable    = dblocal.GetCollection <DocsTag>("DocsTags").FindAll().ToList();
                    var docsReviewsTable = dblocal.GetCollection <DocReview>("DocReviews").FindAll().ToList();

                    book.Docs = (from docsList in docsTable
                                 join docsTagsList in docsTagsTable
                                 on docsList.DocID equals docsTagsList.DocID
                                 join tagsList in book.Tags
                                 on docsTagsList.TagID equals tagsList.TagID
                                 select docsList).ToList();

                    result.Data    = book;
                    result.Success = true;

                    ////Get CSS skill doctag (css skill parent doc id)
                    //var skillDocs = docsTagsTable.ToList().Where(dt => dt.TagID == tagId);
                    //if (skillDocs.Count() > 0)
                    //{
                    //    var skillDoc = skillDocs.First();

                    //    //Get data from children
                    //    var childDocs = new List<Doc>();
                    //    GetChildDocs(docsTable.ToList(), docsReviewsTable.ToList(), getSkillups, skillDoc.DocID);

                    //}
                }
            }
            catch (Exception ex)
            {
                result.Data = ex.Message; // System.Text.Json.JsonSerializer.Serialize<Exception>(ex, new System.Text.Json.JsonSerializerOptions() { MaxDepth = 1000, PropertyNamingPolicy = null } );
            }

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(
            [Bind("Id,Name,Author,AuthorCipher,Grade,Subject,Published,Price,Note")]
            StudyBook studyBook
            )
        {
            if (_context.Books.Any(b => b.Id == studyBook.Id))
            {
                ModelState.AddModelError("Id", "Підручник з даним інвентарним номером все існує");
            }
            if (ModelState.IsValid)
            {
                studyBook.Status = BookStatus.InStock;
                _context.Add(studyBook);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Books"));
            }
            return(View(studyBook));
        }
Ejemplo n.º 3
0
        public Result SaveBook([FromBody] StudyBook book)
        {
            var result = new Result();

            try
            {
                using (var db = new LiteDatabase(studyBooksDB))
                {
                    var books = db.GetCollection <StudyBook>("StudyBook"); //.FindAll().ToList().Where(b => b.ID == bookId);
                    books.Upsert(book);
                    result.Data    = book;
                    result.Success = true;
                }
            }
            catch (Exception ex)
            {
                result.Data = ex;
            }

            return(result);
        }
Ejemplo n.º 4
0
        public Result New()
        {
            var result  = new Result();
            var newBook = new StudyBook();

            try
            {
                using (var db = new LiteDatabase(studyBooksDB))
                {
                    var table = db.GetCollection <StudyBook>("StudyBook");
                    table.Upsert(newBook);

                    result.Data    = newBook;
                    result.Success = true;
                }
            }
            catch (Exception ex)
            {
                result.Data = ex;
            }

            return(result);
        }
Ejemplo n.º 5
0
 public async Task <IActionResult> Edit(
     int curId,
     [Bind("Id,Name,Author,AuthorCipher,Grade,Subject,Published,Price,Note,Status")]
     StudyBook studyBook
     )
 {
     if (_context.Books.Any(b => b.Id == studyBook.Id && b.Id != curId))
     {
         ModelState.AddModelError("Id", "Підручник з даним інвентарним номером все існує");
     }
     if (ModelState.IsValid)
     {
         try
         {
             _context.Update(studyBook);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!StudyBookExists(studyBook.Id))
             {
                 //!todo: Сделать возможным изменение ид книги
                 //await DeleteConfirmed(curId);
                 //return await Create(studyBook);
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction("Index", "Books"));
     }
     studyBook.Id = curId;
     return(View(studyBook));
 }