コード例 #1
0
        public IActionResult User(int projectID, int userID)
        {
            ViewData["Message"] = "The main screen with user info and metrics.";
            TimeTrackerEntityContext db = HttpContext.RequestServices.GetService(typeof(TimeTrackerEntityContext)) as TimeTrackerEntityContext;

            #region Get the Group ID, given the userID and projectID
            List <int> allGroupsForProject = db.GetGroups().FindAll(g => g.ProjectId == projectID).ConvertAll(g => g.GroupId);
            List <int> allGroupsForUser    = db.GetUserProjects().FindAll(u => u.UserId == userID).ConvertAll(g => g.GroupId);
            int        groupID             = 0;
            foreach (int g in allGroupsForUser)
            {
                foreach (int g2 in allGroupsForProject)
                {
                    if (g == g2)
                    {
                        groupID = g;
                    }
                }
            }
            #endregion

            // Populate the viewModel and return a view using it
            UserViewModel viewModel = new UserViewModel()
            {
                selectedUser  = db.GetUsers().Find(u => u.UserId == userID),
                selectedGroup = db.GetGroups().Find(g => g.GroupId == groupID),
                allGroups     = db.GetGroups(),
                timeEntries   = db.GetTimeEntries().FindAll(te => te.UserId == userID && te.GroupId == groupID)
            };
            return(View(viewModel));
        }
コード例 #2
0
        public IActionResult Login(string username, string password)
        {
            TimeTrackerEntityContext db = HttpContext.RequestServices.GetService(typeof(TimeTrackerEntityContext)) as TimeTrackerEntityContext;
            User user = db.GetUsers().Where(dbUser => username == dbUser.ScreenName && dbUser.UserHash == password).First();

            HttpContext.Session.SetInt32("userId", user.UserId);
            return(RedirectToAction("Index"));
            //return View();
        }
コード例 #3
0
        public IActionResult CreateUser(string username, string password, string firstName, string lastName, int groupId)
        {
            TimeTrackerEntityContext db = HttpContext.RequestServices.GetService(typeof(TimeTrackerEntityContext)) as TimeTrackerEntityContext;

            db.addUser(new Models.User()
            {
                ScreenName = username,
                UserHash   = password,
                FirstName  = firstName,
                LastName   = lastName,
                isActive   = true
            });
            db.addUserProject(new UserProject()
            {
                GroupId = groupId,
                UserId  = db.GetUsers().Find(user => user.ScreenName == username).UserId
            });
            HttpContext.Session.SetInt32("userId", db.GetUsers().Find(user => user.ScreenName == username).UserId);

            return(RedirectToAction("Index"));
        }