Example #1
0
        public ActionResult <IEnumerable <CustomTimeLog> > GetTimeLog()
        {
            var timeLog = _context.TimeLog.ToList();

            var projectName = string.Empty;
            var Useremail   = string.Empty;

            List <CustomTimeLog> customTimeLogs = new List <CustomTimeLog>();

            foreach (var log in timeLog)
            {
                projectName = _context.Project.Where(p => p.ProjectId == log.ProjectId).FirstOrDefault().ProjectName;
                Useremail   = _context.UserItems.Where(p => p.UserId == log.UserId).FirstOrDefault().Email;

                CustomTimeLog customTimeLog = new CustomTimeLog
                {
                    TimeLogId   = log.TimeLogId,
                    ProjectName = projectName,
                    Email       = Useremail,
                    Date        = log.Date,
                    Time        = log.Time,
                    Comment     = log.Comment
                };

                customTimeLogs.Add(customTimeLog);
            }

            return(customTimeLogs);
        }
Example #2
0
        public ActionResult <CustomTimeLog> PostTimeLog(CustomTimeLog postTimeLog)
        {
            var projectId = _context.Project.Where(p => p.ProjectName.Equals(postTimeLog.ProjectName)).FirstOrDefault().ProjectId;
            var UserId    = _context.UserItems.Where(p => p.Email.Equals(postTimeLog.Email)).FirstOrDefault().UserId;

            TimeLog timeLog = new TimeLog
            {
                UserId    = UserId,
                ProjectId = projectId,
                Date      = postTimeLog.Date,
                Time      = postTimeLog.Time,
                Comment   = postTimeLog.Comment
            };

            _context.TimeLog.Add(timeLog);
            _context.SaveChangesAsync();

            return(postTimeLog);
            //return CreatedAtAction("GetTimeLog", new { id = timeLog.TimeLogId }, timeLog);
        }