Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        public IActionResult startTrack(DateTime startTime)
        {
            int?id = (int?)(HttpContext.Session.GetInt32("userId")) ?? -1;

            if (id == -1)
            {
                return(RedirectToAction("Login"));
            }
            TimeTrackerEntityContext db = HttpContext.RequestServices.GetService(typeof(TimeTrackerEntityContext)) as TimeTrackerEntityContext;

            db.addTimeEntry(new TimeEntry()
            {
                TimeStart    = startTime,
                CreateDate   = DateTime.UtcNow,
                Deleted      = false,
                EntryComment = "",
                GroupId      = db.GetUserProjects().Where(u => u.UserId == id).FirstOrDefault().GroupId,
                TimeStop     = null,
                UserId       = (int)id
            });
            return(RedirectToAction("TrackTime"));
        }