Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("ActTypeDescrip,ActTypeProd")] ActivityType activityType)
        {
            activityType.Username = User.Identity.Name;

            if (ModelState.IsValid)
            {
                _context.Add(activityType);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(activityType));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("ActivityName,ActivityTypeID")] Activity activity)
        {
            activity.Username = User.Identity.Name;

            if (ModelState.IsValid)
            {
                _context.Add(activity);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["ActivityTypeID"] = new SelectList(_context.ActivityTypes.Where(o => o.Username == User.Identity.Name), "ActivityTypeID", "ActTypeDescrip", activity.ActivityTypeID);
            return(View(activity));
        }
        public async Task <IActionResult> Create([Bind("ActivityID,StartTime,EndTime")] TimeLog timeLog)
        {
            timeLog.Username = User.Identity.Name;

            if (ModelState.IsValid)
            {
                _context.Add(timeLog);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["ActivityID"] = new SelectList(_context.Activities.Where(o => o.Username == User.Identity.Name), "ActivityID", "ActivityName", timeLog.ActivityID);
            return(View(timeLog));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("ActivityID")] TimeLog timeLog)
        {
            if (ModelState.IsValid)
            {
                //get last time log with no end time
                string query = "SELECT TOP 1 * FROM TimeLog WHERE Username = {0} and EndTime is null order by StartTime desc";
                try {
                    var endTimeLog = await _context.TimeLogs
                                     .FromSql(query, User.Identity.Name)
                                     .AsNoTracking()
                                     .SingleOrDefaultAsync();

                    if (endTimeLog != null)
                    {
                        endTimeLog.EndTime = DateTime.Now;
                        _context.Update(endTimeLog);
                        await _context.SaveChangesAsync();
                    }
                } catch (DbUpdateConcurrencyException) {
                    if (!TimeLogExists(timeLog.TimeLogID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                try {
                    timeLog.Username  = User.Identity.Name;
                    timeLog.StartTime = DateTime.Now;
                    _context.Add(timeLog);
                    await _context.SaveChangesAsync();
                } catch {
                }
                return(RedirectToAction("Index"));
            }
            ViewData["ActivityID"] = new SelectList(_context.Activities, "ActivityID", "ActivityID", timeLog.ActivityID);
            return(View(timeLog));
        }