public async Task <IViewComponentResult> InvokeAsync(Guid bookId, Guid?id, string type) { var userId = HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id")?.Value; PredicateBuilder <BookPart> query = new PredicateBuilder <BookPart>(); query.And(x => x.Enabled && x.Approve); if (string.IsNullOrEmpty(userId)) { query.And(x => !x.VIP); } else { var bougth = PersianNovComponent.Instance.CustomerBookFacade.Any(x => x.CustomerId == userId.ToGuid() && x.BookId == bookId); if (!bougth) { query.And(x => !x.VIP); } } if (id != null) { var part = PersianNovComponent.Instance.BookPartFacade.Get(id); switch (type) { case "next": query.And(x => x.PartNumber > part.PartNumber); break; case "per": query.And(x => x.PartNumber < part.PartNumber); break; } } BookPart result = null; if (string.IsNullOrEmpty(type) || type == "next") { result = await PersianNovComponent.Instance.BookPartFacade.FirstOrDefaultWithOrderByAsync(x => x.PartNumber, query.GetExpression()); } else { result = await PersianNovComponent.Instance.BookPartFacade.FirstOrDefaultWithOrderByDescendingAsync(x => x.PartNumber, query.GetExpression()); } if (result == null) { result = PersianNovComponent.Instance.BookPartFacade.Get(id); } return(await Task.FromResult((IViewComponentResult)View("BookParts", result))); }
public IActionResult Delete(BookPart bookPart) { try { if (!PersianNovComponent.Instance.BookPartFacade.Delete(bookPart.Id)) { throw new Exception("خطایی در حذف اطلاعات کتاب رخ داده است"); } return(RedirectToAction("Index", new { bookId = bookPart.BookId })); } catch (Exception ex) { ViewBag.Message = ex.InnerException.Message; return(View(bookPart)); } }
public IActionResult Create(BookPart BookPart) { try { BookPart.PublishDate = DateTime.Now.ShamsiDate(); if (!PersianNovComponent.Instance.BookPartFacade.Insert(BookPart)) { throw new Exception("خطایی در درج اطلاعات کتاب رخ داده است"); } return(RedirectToAction("Index", new { bookId = BookPart.BookId })); } catch (Exception ex) { ViewBag.Message = ex.Message; return(View(BookPart)); } }