Ejemplo n.º 1
0
        public async Task <IActionResult> UpdateTaskAsync(DataModels.TaskLists.Task task, [FromServices] IMongoCollection <DataModels.TaskLists.Task> mongoCollection)
        {
            if (task == null || !task.AreValuesCorrect())
            {
                return(new JsonResult(new { Type = "Error", Details = "Task is null or it's properties are empty!" }));
            }

            DataModels.TaskLists.Task currentValue = await mongoCollection.FirstOrDefaultAsync(x => x.ID == task.ID);

            if (currentValue == null)
            {
                return(new JsonResult(new { Type = "Error", Details = "Task's ID has been altered or such Task never existed! Update failed!" }));
            }

            UpdateResult result = await mongoCollection.UpdateOneAsync(x => x.ID == task.ID, Extensions.GenerateUpdateDefinition(currentValue, task));

            if (result.IsAcknowledged)
            {
                return(new JsonResult(new { Type = "Success", Details = "" }));
            }
            else
            {
                return(new JsonResult(new { Type = "Error", Details = "Update somehow failed!" }));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateTaskAsync(DataModels.TaskLists.Task task,
                                                          [FromServices] IMongoCollection <DataModels.TaskLists.Task> mongoCollection)
        {
            if (task == null || !task.AreValuesCorrect())
            {
                return(this.Error(HttpStatusCode.UnprocessableEntity, "Task is null or it's properties are empty!"));
            }

            DataModels.TaskLists.Task currentValue = await mongoCollection.FirstOrDefaultAsync(x => x.ID == task.ID);

            if (currentValue == null)
            {
                return(this.Error(HttpStatusCode.UnprocessableEntity,
                                  "Task's Id has been altered or such Task never existed! Update failed!"));
            }

            UpdateResult result = await mongoCollection.UpdateOneAsync(x => x.ID == task.ID,
                                                                       Extensions.GenerateUpdateDefinition(currentValue, task));

            if (result.IsAcknowledged)
            {
                return(this.Success(""));
            }
            else
            {
                return(this.Error(HttpStatusCode.InternalServerError, "Update somehow failed!"));
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> AddTaskAsync(DataModels.TaskLists.Task task, [FromServices] IMongoCollection <DataModels.TaskLists.Task> mongoCollection)
        {
            if (task == null || !task.AreValuesCorrect())
            {
                return(new JsonResult(new { Type = "Error", Details = "Task is null or it's properties are empty!" }));
            }
            task.ID = Guid.NewGuid();
            await mongoCollection.InsertOneAsync(task);

            return(new JsonResult(new { Type = "Success", Details = task.ID }));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> AddTaskAsync(DataModels.TaskLists.Task task,
                                                       [FromServices] IMongoCollection <DataModels.TaskLists.Task> mongoCollection)
        {
            if (task == null || !task.AreValuesCorrect())
            {
                return(this.Error(HttpStatusCode.UnprocessableEntity, "Task is null or it's properties are empty!"));
            }
            task.ID = Guid.NewGuid();
            await mongoCollection.InsertOneAsync(task);

            return(this.Success(task.ID));
        }