Example #1
0
        public IActionResult AddRequest(UserProductRequest upr)
        {
            if (ModelState.IsValid)
            {
                _db.UserProductRequest.Add(upr);

                _db.SaveChanges();

                var request = from
                              r in _db.UserProductRequest
                              join u in _db.SprUser on r.UserId equals u.Id
                              join p in _db.SprProduct on r.ProductId equals p.Id
                              select
                              new { r.Id, u.FirstName, u.LastName, p.ProductName, r.ProductAmount };
                request = request.Where(r => r.Id == upr.Id);

                upr.setProductName(request.First().ProductName);
                upr.setUserName(request.First().FirstName + " " + request.First().LastName);

                return(View(upr));
            }
            else
            {
                var users    = from i in _db.SprUser select i;
                var products = from i in _db.SprProduct select i;

                ViewBag.usersCol    = users;
                ViewBag.productsCol = products;

                return(View("Index"));
            }
        }   //  AddRequest()
Example #2
0
        public void AddRequest()
        {
            // Arrange
            StationeryContext sc         = new StationeryContext();
            HomeController    controller = new HomeController(sc);

            UserProductRequest upr = new UserProductRequest();

            upr.ProductId     = 1;
            upr.UserId        = 1;
            upr.ProductAmount = 1;

            // Act
            ViewResult result = controller.AddRequest(upr) as ViewResult;

            // Assert
            Assert.IsType <ViewResult>(result);
        }