public ActionResult _AjaxRentBook(RentBookDTO dto)
        {
            var bookInfo = ApiRequestWithFormUrlEncodedContent.Get <EditBookDTO>($"{_inventoryApiBaseUrl}/api/Books/{dto.BookId}");

            var bookInventoryId = bookInfo.BookInventories.Where(p => p.Status == 1).FirstOrDefault()?.BookInventoryId;

            if (bookInventoryId.HasValue)
            {
                var commandId = ApiRequestWithStringContent.Post <Guid>($"{_rentalApiBaseUrl}/api/customers/{dto.CustomerId}/books", new
                {
                    BookId     = bookInventoryId,
                    BookName   = bookInfo.BookName,
                    ISBN       = bookInfo.ISBN,
                    CustomerId = dto.CustomerId,
                    Name       = new
                    {
                        FirstName  = "Lily",
                        MiddleName = string.Empty,
                        LastName   = "Jiang"
                    }
                });

                return(Json(new { result = true, commandId = commandId }));
            }
            else
            {
                return(Json(new { result = false, errorMessage = "Book has been rented, please try again." }));
            }
        }
Beispiel #2
0
        public ActionResult Add(AddBookDTO dto)
        {
            var data = new NameValueCollection();

            data.Add("BookName", dto.BookName);
            data.Add("ISBN", dto.ISBN);
            data.Add("IssueDate", dto.IssueDate.ToString("yyyy-MM-dd"));
            data.Add("Description", dto.Description);

            var commandUnqiueId = ApiRequestWithFormUrlEncodedContent.Post <Guid>($"{_inventoryApiBaseUrl}/api/Books", data);

            return(Json(new { commandUnqiueId = commandUnqiueId }));
        }
Beispiel #3
0
        public ActionResult Edit(Guid id, EditBookDTO dto)
        {
            var data = new NameValueCollection();

            data.Add("BookId", dto.BookId.ToString());
            data.Add("BookName", dto.BookName);
            data.Add("ISBN", dto.ISBN);
            data.Add("IssueDate", dto.DateIssued.ToString("yyyy-MM-dd"));
            data.Add("Description", dto.Description);

            var commandId = ApiRequestWithFormUrlEncodedContent.Put <Guid>($"{_inventoryApiBaseUrl}/api/Books/{dto.BookId}", data);

            if (commandId != Guid.Empty)
            {
                return(RedirectToAction("List"));
            }
            else
            {
                return(View(dto));
            }
        }
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            var url = $"{_identityApiBaseUrl}/api/identities";

            var datas = new NameValueCollection();

            datas.Add("UserName", model.UserName);
            datas.Add("Password", model.Password);

            var validationResult = ApiRequestWithFormUrlEncodedContent.Post <IdentityDTO>(url, datas);

            if (validationResult != null && validationResult.UserId != Guid.Empty)
            {
                FormsAuthentication.SetAuthCookie(validationResult.UserId.ToString(), false);
                return(RedirectToAction("List", "Book"));
            }
            else
            {
                ModelState.AddModelError("LoginFailure", "User is not existed or password is wrong.");
                return(View());
            }
        }
Beispiel #5
0
        public ActionResult _AjaxGetAvailableBooks()
        {
            var data = ApiRequestWithFormUrlEncodedContent.Get <List <AvailableBookModel> >($"{_inventoryApiBaseUrl}/api/available_books");

            return(Json(data, JsonRequestBehavior.AllowGet));
        }
Beispiel #6
0
        public ActionResult Edit(Guid id)
        {
            var data = ApiRequestWithFormUrlEncodedContent.Get <EditBookDTO>($"{_inventoryApiBaseUrl}/api/Books/{id}");

            return(View(data));
        }
Beispiel #7
0
        public ActionResult List()
        {
            var data = ApiRequestWithFormUrlEncodedContent.Get <List <BookViewModel> >($"{_inventoryApiBaseUrl}/api/Books");

            return(View(data));
        }
        public ActionResult UnreturnedBooks()
        {
            var data = ApiRequestWithFormUrlEncodedContent.Get <List <UnreturnedBookViewModel> >($"{_rentalApiBaseUrl}/api/unreturned_books");

            return(View(data));
        }
Beispiel #9
0
        // GET: Customer
        public ActionResult _AjaxGetAllCustomers()
        {
            var data = ApiRequestWithFormUrlEncodedContent.Get <List <CustomerViewModel> >($"{_identityApiBaseUrl}/api/customers");

            return(Json(data, JsonRequestBehavior.AllowGet));
        }