Example #1
0
        public string AddBookToUser(UserToBookDTO userToBookDTO)
        {
            if (!UtBService.Save(userToBookDTO))
            {
                return("Book wasn't added to User");
            }

            return("Book was added to User");
        }
Example #2
0
        public ActionResult Download(int Id)
        {
            if (Session["loggedUser"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            UserDTO current = (UserDTO)Session["loggedUser"];

            Service1Client service = new Service1Client();

            UserToBookDTO download = new UserToBookDTO()
            {
                bookUser = service.GetUserById(current.Id),
                Book     = service.GetBookById(Id)
            };

            service.AddBookToUser(download);

            return(RedirectToAction("Index", "Book"));
        }
        public bool Save(UserToBookDTO userToBookDTO)
        {
            if (userToBookDTO == null)
            {
                return(false);
            }

            UserToBook userToBook = new UserToBook
            {
                UserId = userToBookDTO.bookUser.Id,
                BookId = userToBookDTO.Book.Id
            };

            try
            {
                UoW.UserToBookRepo.Insert(userToBook);
                UoW.Save();
                return(true);
            }
            catch
            {
                return(false);
            }
        }