Beispiel #1
0
        public IActionResult Index(TimeLogViewModel vm)
        {
            if (ModelState.IsValid)
            {
                // Get the maximum PK in Log
                int maxLogId = 0;

                if (_context.Log.Any())
                {
                    maxLogId = _context.Log.Max(t => t.LogId);
                }

                // Get the maximum PK in UserLog
                int userLogMaxId = 0;

                if (_context.UserLog.Any())
                {
                    userLogMaxId = _context.UserLog.Max(t => t.UserLogId);
                }

                // The date selected by the user (goes in Log)
                DateTime enteredDate = DateTime.Parse(vm.date);

                // Write the Log record
                Log Log = new Log
                {
                    Date     = enteredDate,
                    TimeInId = vm.TimeInID
                };
                _context.Add(Log);
                _context.SaveChanges();


                int tempLogId = 0;
                tempLogId = (maxLogId + 1);

                int count = (vm.SelectedIDArray).Count;

                UserLog[] tempULog = new UserLog[count];
                string[]  userkeys = new string[count];
                userkeys = (vm.SelectedIDArray).ToArray();

                for (int i = 0; i < ((vm.SelectedIDArray).Count); i++)
                {
                    userLogMaxId += 1;
                    tempULog[i]   = TimeLogSupport.createUserLogRecord(tempLogId, userkeys[i], userLogMaxId);
                    _context.Add(tempULog[i]);
                }

                _context.SaveChanges();

                return(RedirectToAction("ShowLog", vm));
            }

            return(View());
        }
Beispiel #2
0
        public IActionResult DisplayLog(TimeLogViewModel vm)
        {
            DateTime tempDate = DateTime.Parse(vm.date);

            ViewBag.TheDate = tempDate;

            TimeLogSupport timeLogSupport = new TimeLogSupport(_context);

            return(RedirectToAction("ShowLog", vm));
        }
Beispiel #3
0
        public IActionResult ShowLog(DateTime date, TimeLogViewModel vm)
        {
            TimeLogSupport timeLogSupport = new TimeLogSupport(_context);

            string dt = date.ToString("yyyy/MM/dd");

            ViewBag.TheDate = dt;

            ViewBag.TheCategory = timeLogSupport.getTimeInCategory(vm.TimeInID);

            return(View(timeLogSupport.getUserName(vm)));
        }