예제 #1
0
        public async Task <IActionResult> PutSchedulerTable(Guid id, [FromBody] SchedulerTable schedulerTable)
        {
            var schedule = await _context.Schedulers.FindAsync(id);

            if (schedule == null)
            {
                return(BadRequest($"Schedule with ID:{id} does not exit."));
            }

            schedule.ScheduleConfiguration = schedulerTable.ScheduleConfiguration;
            schedule.IsScheduled           = schedulerTable.IsScheduled;
            schedule.LastRan     = schedulerTable.LastRan;
            schedule.LastUpdated = DateTime.Now;


            _context.Entry(schedule).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SchedulerTableExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #2
0
        public async Task <ActionResult <SchedulerTable> > PostSchedulerTable([FromBody] SchedulerTable schedulerTable)
        {
            var user = await _context.Users.FindAsync(schedulerTable.UserId);

            if (user == null)
            {
                return(BadRequest($"User with ID:{schedulerTable.UserId} does not exist."));
            }

            SchedulerTable newSchedulerTable = new SchedulerTable
            {
                ScheduleId            = new Guid(),
                ScheduleConfiguration = schedulerTable.ScheduleConfiguration,
                IsScheduled           = schedulerTable.IsScheduled,
                LastRan     = null,
                Created     = DateTime.Now,
                LastUpdated = DateTime.Now,
                UserId      = schedulerTable.UserId,
                User        = schedulerTable.User
            };


            _context.Schedulers.Add(newSchedulerTable);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetSchedulerTable", new { id = newSchedulerTable.ScheduleId }, newSchedulerTable));
        }