示例#1
0
        public ActionResult Index(string search_string)
        {
            string          user_id   = User.Identity.GetUserId();
            ApplicationUser real_user = Repo.Context.Users.FirstOrDefault(u => u.Id == user_id);
            ToolshedUser    me        = null;

            try
            {
                me = Repo.GetAllUsers().Where(u => u.RealUser.Id == user_id).Single();
            }
            catch (Exception)
            {
                bool successful = Repo.AddNewUser(real_user);
                if (successful)
                {
                    me = Repo.GetAllUsers().Where(u => u.RealUser.Id == user_id).Single();
                }
            }

            List <Tool> others_tools = Repo.GetOthersAvailableTools(me);
            var         search_tools = from t in others_tools where t.Owner.UserId != me.UserId select t;

            if (!String.IsNullOrEmpty(search_string))
            {
                search_tools = search_tools.Where(t => Regex.IsMatch(t.Name, search_string, RegexOptions.IgnoreCase) || Regex.IsMatch(t.Owner.FirstName, search_string, RegexOptions.IgnoreCase) || t.Description.Contains(search_string) || Regex.IsMatch(t.Category, search_string, RegexOptions.IgnoreCase));

                return(View(search_tools));
            }
            else
            {
                return(View(others_tools));
            }
        }
示例#2
0
        // GET: Tools/Borrow
        public ActionResult Borrow(int?id)
        {
            string          user_id   = User.Identity.GetUserId();
            ApplicationUser real_user = Repo.Context.Users.FirstOrDefault(u => u.Id == user_id);
            ToolshedUser    me        = null;

            try
            {
                me = Repo.GetAllUsers().Where(u => u.RealUser.Id == user_id).Single();
            }
            catch (Exception)
            {
                bool successful = Repo.AddNewUser(real_user);
                if (successful)
                {
                    me = Repo.GetAllUsers().Where(u => u.RealUser.Id == user_id).Single();
                }
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Tool tool = Repo.Context.Tools.Find(id);

            if (tool == null)
            {
                return(HttpNotFound());
            }
            tool.Available = false;
            tool.Borrowed  = true;
            tool.Borrower  = me;
            Repo.Context.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#3
0
        public ActionResult DeleteConfirmed(int id)
        {
            ToolshedUser toolshedUser = db.ToolshedUsers.Find(id);

            db.ToolshedUsers.Remove(toolshedUser);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#4
0
 public ActionResult Edit([Bind(Include = "UserId,FirstName,LastName,UserName,Phone,Street")] ToolshedUser toolshedUser)
 {
     if (ModelState.IsValid)
     {
         db.Entry(toolshedUser).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(toolshedUser));
 }
示例#5
0
        // GET: ToolshedUsers/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ToolshedUser toolshedUser = db.ToolshedUsers.Find(id);

            if (toolshedUser == null)
            {
                return(HttpNotFound());
            }
            return(View(toolshedUser));
        }
示例#6
0
        public ActionResult Create([Bind(Include = "UserId,FirstName,LastName,UserName,Phone,Street")] ToolshedUser toolshedUser)
        {
            string          user_id   = User.Identity.GetUserId();
            ApplicationUser real_user = Repo.Context.Users.FirstOrDefault(u => u.Id == user_id);


            if (ModelState.IsValid)
            {
                Repo.CreateToolshedUser(real_user, toolshedUser.FirstName, toolshedUser.LastName, toolshedUser.UserName, toolshedUser.Phone, toolshedUser.Street);
                return(RedirectToAction("_MyTools", "Tools"));
            }

            return(RedirectToAction("Create", "ToolshedUsers"));
        }
示例#7
0
        public ActionResult Create([Bind(Include = "Owner,ToolId,Name,Category,Description,Image")] Tool tool)

        {
            string          user_id   = User.Identity.GetUserId();
            ApplicationUser real_user = Repo.Context.Users.FirstOrDefault(u => u.Id == user_id);
            ToolshedUser    me        = Repo.GetAllUsers().Where(u => u.RealUser.Id == user_id).SingleOrDefault();

            if (ModelState.IsValid)
            {
                Repo.CreateTool(me, tool.Name, tool.Category, tool.Description, tool.Image);
            }

            return(RedirectToAction("Index"));
        }
示例#8
0
        public void ToolshedUserEnsureJitterUserHasAllTheThings()
        {
            // Arrange
            ToolshedUser a_user = new ToolshedUser();

            a_user.UserId    = 1;
            a_user.FirstName = "Jim";
            a_user.LastName  = "Beam";
            a_user.Phone     = "111-222-3333";
            a_user.Street    = "Anystreet Blvd";

            // Assert
            Assert.AreEqual(1, a_user.UserId);
            Assert.AreEqual("111-222-3333", a_user.Phone);
            Assert.AreEqual("Jim", a_user.FirstName);
            Assert.AreEqual("Beam", a_user.LastName);
            Assert.AreEqual("Anystreet Blvd", a_user.Street);
        }
示例#9
0
        public ActionResult MyBorrowed()
        {
            string          user_id   = User.Identity.GetUserId();
            ApplicationUser real_user = Repo.Context.Users.FirstOrDefault(u => u.Id == user_id);
            ToolshedUser    me        = null;

            try
            {
                me = Repo.GetAllUsers().Where(u => u.RealUser.Id == user_id).Single();
            }
            catch (Exception)
            {
                bool successful = Repo.AddNewUser(real_user);
            }

            List <Tool> my_tools = Repo.GetListOfToolsThisUserBorrowed(me);

            return(View(my_tools));
        }
        public void ToolshedRepositoryGetUserByUserNameFailsMultipleUsers()
        {
            // Arrange
            var expected = new List <ToolshedUser>
            {
                new ToolshedUser {
                    UserName = "******"
                },
                new ToolshedUser {
                    UserName = "******"
                }
            };

            mock_set.Object.AddRange(expected);

            ConnectMocksToDataStore(expected);
            // Act
            string       username    = "******";
            ToolshedUser actual_user = repository.GetUserByUserName(username);
            // Assert
        }
        public void ToolshedRepositoryGetUserByUserNameUserDoesNotExist()
        {
            // Arrange
            var expected = new List <ToolshedUser>
            {
                new ToolshedUser {
                    UserName = "******"
                },
                new ToolshedUser {
                    UserName = "******"
                }
            };

            mock_set.Object.AddRange(expected);

            ConnectMocksToDataStore(expected);
            // Act
            string       username    = "******";
            ToolshedUser actual_user = repository.GetUserByUserName(username);

            // Assert
            Assert.IsNull(actual_user);
        }
        public void ToolshedRepositoryEnsureICanGenUserByUserName()
        {
            // Arrange
            var expected = new List <ToolshedUser>
            {
                new ToolshedUser {
                    UserName = "******"
                },
                new ToolshedUser {
                    UserName = "******"
                }
            };

            mock_set.Object.AddRange(expected);

            ConnectMocksToDataStore(expected);
            // Act
            string       username    = "******";
            ToolshedUser actual_user = repository.GetUserByUserName(username);

            // Assert
            Assert.AreEqual("shoprat", actual_user.UserName);
        }
        public void ToolshedRepositoryEnsureICanAddATool()
        {
            // Arrange

            List <Tool> expected_tools = new List <Tool>(); // This is our database

            ConnectMocksToDataStore(expected_tools);
            ToolshedUser toolshed_user1 = new ToolshedUser {
                UserName = "******"
            };
            string name     = "Compressor";
            string category = "Power Tool";
            string descrip  = "10gal 1.25hp";
            string pic      = "https://google.com";

            mock_tool_set.Setup(t => t.Add(It.IsAny <Tool>())).Callback((Tool s) => expected_tools.Add(s));
            // Act
            bool successful = repository.CreateTool(toolshed_user1, name, category, descrip, pic);

            // Assert
            Assert.AreEqual(1, repository.GetAllTools().Count);
            // Should this return true?
            Assert.IsTrue(successful);
        }
示例#14
0
        public void ToolshedUserEnsureICanCreateInstance()
        {
            ToolshedUser a_user = new ToolshedUser();

            Assert.IsNotNull(a_user);
        }