Esempio n. 1
0
        public ActionResult RequestBook(String bookId,String userId)
        {
            try
            {
                int userid = Convert.ToInt32(userId);
                int bookCode = Convert.ToInt32(bookId);
                Boolean sessionState = sessionObj.CheckSession(userid);

                if (sessionState)
                {
                    IUserService userService = new UserService();
                    User user = userService.GetUserById(userid);
                    IBookService bookService = new BookService();
                    Book book = bookService.GetById(bookCode);
                    Boolean status = bookService.BookRequest(book, user);

                    if (status)
                    {
                        return Content("Success");
                    }
                    return Content("Failed");
                }

                return View("Error");
            }

            catch (Exception e)
            {
                Console.WriteLine("Error");
                Console.Write(e.ToString());
                return View("Error");
            }
        }
Esempio n. 2
0
        public Boolean Add(int userid, int bookid)
        {
            try
            {
                var bookRequestService = new BookRequestService();
                BookRequest bookRequest = bookRequestService.GetByBook(bookid);

                var userService = new UserService();
                User user = userService.GetUserById(userid);

                var userBookRequest = new UserBookRequest {User = user, BookRequest = bookRequest, IsActive = 1};

                IList<UserBookRequest> userBookRequestList = new List<UserBookRequest>();
                userBookRequestList.Add(userBookRequest);

                var userBookRequestDal = new UserBookRequestDal();
                Boolean status = userBookRequestDal.Save(userBookRequestList);

                return status;

            }
            catch (Exception e)
            {
                Console.WriteLine("Some error in UserBookRequestService , Add()");
                Console.Write(e.ToString());
                return false;
            }
        }
Esempio n. 3
0
        public ActionResult Login(String username , String password)
        {
            IUserService service = new UserService();

            UserDto retUserDto = service.ValidateUser(username,password);

            String json = new JavaScriptSerializer().Serialize(retUserDto);

            if (retUserDto == null)
            {
                return Content("null");
            }
            else
            {
                try
                {
                    Session session = sessionObj.CreateSession(retUserDto);

                    if (session != null)
                        return Content(retUserDto.Id.ToString());
                    else
                        return Content("error");
                }
                catch (Exception e)
                {
                    Console.WriteLine("Session could not be created");
                    return Content("existing");
                }
            }
        }
Esempio n. 4
0
        //        [TestMethod]
        public void TestGetById()
        {
            IUserService userService = new UserService();
            User user = userService.GetUserById(20);

            Assert.IsNotNull(user);

            Console.WriteLine(user.Age);
        }
Esempio n. 5
0
        //          [TestMethod]
        public void TestValidateUser()
        {
            UserService service = new UserService();
            String username = "******";
            String password = "******";

            UserDto dto = service.ValidateUser(username, password);
            String json = new JavaScriptSerializer().Serialize(dto);
            Console.Write(json);
        }
Esempio n. 6
0
        //        [TestMethod]
        public void TestUserService()
        {
            UserService uservice = new UserService();
            User user = new User();

            user.Name = "Abhishek";
            user.Password = "******";

            //        Assert.AreEqual(user,uservice.Create("Abhishek",24,"abhi","1234"));
        }
Esempio n. 7
0
        public void TestCreateUser()
        {
            String username = "******";
            String password = "******";
            UserService service = new UserService();
            UserDto dto = service.ValidateUser(username, password);
            SessionService sessionService = new SessionService();
            Session session = sessionService.CreateSession(dto);

            Console.WriteLine(session.Name);
        }
Esempio n. 8
0
 public void TestUserSearch()
 {
     String searchString = "q3";
     IUserService userService = new UserService();
     IList<UserBookRequest> returnedList  = userService.UserSearch(searchString);
     foreach (var ubr in returnedList)
     {
         Console.WriteLine(ubr.BookRequest.Book.Name);
     }
     Assert.IsNotNull(returnedList);
 }
Esempio n. 9
0
        //        [TestMethod]
        public void TestBookRequest()
        {
            IBookService bookService = new BookService();
            Book book = bookService.GetById(15);
            IUserService userService = new UserService();
            User user = userService.GetUserById(20);

            Boolean status = bookService.BookRequest(book, user);

            Assert.IsTrue(status);
        }
Esempio n. 10
0
        public Session TestCreateSession()
        {
            IPrepareSession preSession = new PrepareSession();
            String username = "******";
            String password = "******";
            UserService service = new UserService();
            UserDto dto = service.ValidateUser(username, password);
            SessionObjects sessionObjects = SessionObjects.CreateInstance();
            Session session = sessionObjects.CreateSession(dto);

            Console.WriteLine(session.Age);

            Assert.IsNotNull(session);
            return session;
        }
Esempio n. 11
0
        public void TestPrepare()
        {
            IPrepareSession preSession = new PrepareSession();
            String username = "******";
            String password = "******";

            UserService service = new UserService();

            UserDto dto = service.ValidateUser(username, password);

            Session session = preSession.Prepare(dto);

            Console.Write(dto.Name);

            Console.Write(session.Name);

            Assert.IsNotNull(session, "Should not be null");
        }
Esempio n. 12
0
        public ActionResult CreateUser(User user)
        {
            try
            {
                IUserService service = new UserService();

                Boolean status = service.Create(user); // Fire the query

                if (status)
                {
                    return Content("Success");
                }
                    return Content("Error");
            }

            catch (Exception e)
            {
                Console.Write("Error creating user");
                return Content("Error");
            }
        }
Esempio n. 13
0
 public ActionResult SearchUser(String userId, String searchString)
 {
     try
     {
         ViewBag.userId = userId;
         IUserService userService = new UserService();
         IList<UserBookRequest> userList = userService.UserSearch(searchString);
         return View(userList);
     }
     catch (Exception e)
     {
         Console.WriteLine("SearchUser Error");
         Console.Write(e.ToString());
         return Content("Error");
     }
 }