public async Task <IActionResult> UpdateNewTask(RepairTaskPost rt, int taskId)
        {
            // Check that task exists
            if (await _repairTaskService.GetByTaskId(taskId) == null)
            {
                return(BadRequest("task doesnt exist"));
            }

            // Check that task criticality is correct
            if (rt.Criticality < 1 || rt.Criticality > 3)
            {
                return(StatusCode(400, "Bad criticality value"));
            }
            // Check completed field correctness
            if (rt.Completed < 0 || rt.Completed > 1)
            {
                return(StatusCode(400, "Bad completed value"));
            }
            var queryresult = await _repairTaskService.UpdateTask(rt, taskId);

            return(Ok(new RepairTaskDto
            {
                TaskId = queryresult.TaskId,
                DeviceId = queryresult.DeviceId,
                DateAdded = queryresult.DateAdded,
                Description = queryresult.Description,
                Criticality = queryresult.Criticality,
                Completed = queryresult.Completed
            }));
        }
Пример #2
0
        public async Task <RepairTask> UpdateTask(RepairTaskPost task, int taskId)
        {
            var oldTask = _dbContext.RepairTasks.Where(rt => rt.TaskId == taskId).First();

            if (task.DeviceId.ToString() != "")
            {
                oldTask.DeviceId = task.DeviceId;
            }
            oldTask.DateAdded   = DateTime.Now; // Update also timestamp
            oldTask.Description = task.Description;
            oldTask.Criticality = task.Criticality;
            oldTask.Completed   = task.Completed;
            await _dbContext.SaveChangesAsync();

            return(oldTask);
        }
Пример #3
0
        public async Task <RepairTask> AddTask(RepairTaskPost rt)
        {
            // Ignore datetime-input from user and use system time instead
            // so format is always same
            RepairTask repairTask = new RepairTask
            {
                DeviceId    = rt.DeviceId,
                DateAdded   = DateTime.Now,
                Description = rt.Description,
                Criticality = rt.Criticality,
                Completed   = rt.Completed
            };

            await _dbContext.RepairTasks.AddAsync(repairTask);

            await _dbContext.SaveChangesAsync();

            return(repairTask);
        }
        public async Task <IActionResult> PostNewTask(RepairTaskPost rt)
        {
            // Check that task criticality is correct
            if (rt.Criticality < 1 || rt.Criticality > 3)
            {
                return(StatusCode(400, "Bad criticality value"));
            }
            // Check completed field correctness
            if (rt.Completed < 0 || rt.Completed > 1)
            {
                return(StatusCode(400, "Bad completed value"));
            }
            var queryresult = await _repairTaskService.AddTask(rt);

            return(Ok(new RepairTaskDto
            {
                TaskId = queryresult.TaskId,
                DeviceId = queryresult.DeviceId,
                DateAdded = queryresult.DateAdded,
                Description = queryresult.Description,
                Criticality = queryresult.Criticality,
                Completed = queryresult.Completed
            }));
        }