Esempio n. 1
0
        public async Task <IActionResult> PutTaskAsync(int id, [FromBody] PutTaskRequest request)
        {
            Logger?.LogDebug("'{0}' has been invoked", nameof(PutTaskAsync));
            var response = new Response();

            try
            {
                var entity = await DbContext.GetTaskAsync(new Task(id));

                if (entity == null)
                {
                    return(NotFound());
                }

                entity.Name = request.Name;

                DbContext.Update(entity);

                await DbContext.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = "There was an internal error, please contact to technical support.";

                Logger?.LogCritical("There was an error on '{0}' invocation: {1}", nameof(PutTaskAsync), ex);
            }

            return(response.ToHttpResponse());
        }
Esempio n. 2
0
        public async Task <TaskGetResponse> PutTask(int taskId, PutTaskRequest task)
        {
            using (var connection = new SqlConnection(_connectionString))
            {
                await connection.OpenAsync();

                await connection.ExecuteAsync
                (
                    @"EXEC dbo.Put_Task
                    @TaskId = @TaskId, @Title = @Title, @Content = @Content",
                    new { TaskId = taskId, task.Title, task.Content }
                );

                return(await GetTask(taskId));
            }
        }
        public string PutTaskIsCompleted([Microsoft.AspNetCore.Mvc.FromBody] PutTaskRequest message)
        {
            var task = db.Tasks.FirstOrDefault(x => x.Id == message.Id);

            if (task != null)
            {
                task.IsCompleted = true;
                db.SaveChanges();
            }
            else
            {
                {
                    return("Not found");
                }
            }

            return("Updated, Success!");
        }