Exemplo n.º 1
0
        public void UpdateStatus(IEnumerable <Guid> ids, ReminderItemStatus status)
        {
            var patchDocument = new JsonPatchDocument <ReminderItemUpdateModel>(new List <Operation <ReminderItemUpdateModel> >
            {
                new Operation <ReminderItemUpdateModel>
                {
                    op    = "replace",
                    path  = "/status",
                    value = (int)status
                }
            },

                                                                                new Newtonsoft.Json.Serialization.DefaultContractResolver());

            var model = new ReminderItemsUpdateModel
            {
                Ids           = ids.ToList(),
                PatchDocument = patchDocument
            };

            var content = JsonConvert.SerializeObject(model);

            var result = CallWebApi("PATCH", "/api/reminders", content);

            if (result.StatusCode != System.Net.HttpStatusCode.NoContent)
            {
                throw CreateException(result);
            }
        }
        public IActionResult UpdateReminderStatus([FromBody] ReminderItemsUpdateModel reminderItemsUpdateModel)
        {
            if (reminderItemsUpdateModel == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var reminderItemModelToPatch = new ReminderItemUpdateModel();

            reminderItemsUpdateModel.PatchDocument.ApplyTo(reminderItemModelToPatch);

            _reminderStorage.UpdateStatus(reminderItemsUpdateModel.Ids, reminderItemModelToPatch.Status);

            return(NoContent());
        }