Esempio n. 1
0
        public async Task<User> Authenticate(string Username, string Password)
        {
            string passwordKey = Password;
            if (string.IsNullOrEmpty(Username) || string.IsNullOrEmpty(passwordKey))
            {
                return null;
            }

          
             
            // find the user from db with the same username

            var user = _onlineTimeTrackContext.Users.SingleOrDefault(x => x.Username == Username);

            if (user == null)
            {
                throw new Exception("The user is not registered.");
            }

            // generate hash using the user's passwordKey and the given password
            var hash = GenerateHash(Password, user.PasswordKey);

            // see if the hash matches with the one stored in DB
            if (hash == user.PasswordHash)
            {
                // generate token
                GenerateUserToken(user);

                await _onlineTimeTrackContext.SaveChangesAsync();

            }

            return user;
        }
Esempio n. 2
0
        public async Task <Project> UpdateProject(Project ProjectID)
        {
            _onlineTimeTrackContext.Projects.Update(ProjectID);
            await _onlineTimeTrackContext.SaveChangesAsync();

            var ExistingProject = _onlineTimeTrackContext.Projects.FirstOrDefault(x => x.ProjectID == ProjectID.ProjectID);

            return(ExistingProject);
        }
        public async Task <Worklog> Worklog(Worklog worklog)
        {
            // save the worklog
            var Worklog = await _onlineTimeTrackContext.Worklogs.AddAsync(worklog);

            worklog.Feature      = worklog.Feature;
            worklog.DateAdded    = DateTime.UtcNow;
            worklog.DateModified = DateTime.UtcNow;
            await _onlineTimeTrackContext.SaveChangesAsync();

            // return the worklog
            return(worklog);
        }
        public async Task <Timelog> Timelog(Timelog timelog)
        {
            // save the Timelog
            var Timelog = await _onlineTimeTrackContext.Timelogs.AddAsync(timelog);

            timelog.WorklogID = timelog.WorklogID;

            timelog.ActualWorkTimeStart = timelog.ActualWorkTimeStart;

            timelog.ActualWorkTimeEnd = timelog.ActualWorkTimeEnd;
            timelog.DateAdded         = DateTime.UtcNow;
            timelog.DateModified      = DateTime.UtcNow;

            await _onlineTimeTrackContext.SaveChangesAsync();

            // return thetimelog
            return(timelog);
        }