Ejemplo n.º 1
0
        public ActionResult CreateWorkLog(WorkLogModel vm)
        {
            tblWorkLog workLog = new tblWorkLog();

            int UserId = Convert.ToUInt16((this.User.Identity as System.Security.Claims.ClaimsIdentity).FindFirst("UserId").Value);

            if (vm.IsEdit)
            {
                workLog = _context.tblWorkLogs.SingleOrDefault(x => x.WorkLogId == vm.WorkLogId);
            }

            workLog.TaskId    = vm.TaskId;
            workLog.StartTime = Convert.ToDateTime(vm.StartTime);
            workLog.EndTime   = Convert.ToDateTime(vm.EndTime);
            workLog.Duration  = Convert.ToDecimal(workLog.EndTime.Value.Subtract(workLog.StartTime.Value).TotalMinutes);
            workLog.Unit      = vm.Unit;
            if (workLog.Duration != 0 && vm.Unit != 0)
            {
                workLog.AverageTime = vm.Unit / workLog.Duration;
            }

            if (!vm.IsEdit)
            {
                workLog.CreatedById = UserId;
                _context.tblWorkLogs.Add(workLog);
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", new { area = "WorkLog" }));
        }
Ejemplo n.º 2
0
        public int StartTask(int taskId, int userId, string timeStamp)
        {
            var wo = new tblWorkLog();

            wo.TaskId      = taskId;
            wo.StartTime   = Convert.ToDateTime(timeStamp);
            wo.CreatedById = userId;
            _context.tblWorkLogs.Add(wo);
            _context.SaveChanges();

            return(wo.WorkLogId);
        }