示例#1
0
        private void UpdateModelItems(ListModel model)
        {
            if (model != null)
            {
                //get list items from services
                var listItems               = _listItemServices.GetByList(model);
                var matchingItems           = model.Items.Where(li => listItems.Any(i => i.Id == li.Id));
                var nonMatchingNewItems     = model.Items.Where(li => !listItems.Any(i => i.Id == li.Id));
                var nonMatchingDeletedItems = listItems.Where(li => !model.Items.Any(i => i.Id == li.Id));

                matchingItems.ToList().ForEach(li => _listItemServices.Update(li));
                nonMatchingNewItems.ToList().ForEach(li => { li.ListId = model.Id; _listItemServices.Create(li); });
                nonMatchingDeletedItems.ToList().ForEach(li => _listItemServices.Delete(li));
            }
        }
示例#2
0
        public IActionResult Put(int listId, int id, [FromBody] ListItemApiModel value)
        {
            if (listId != _listItemServices.Owner(id))
            {
                return(BadRequest());
            }

            var retval = _listItemServices.Read(id);

            if (retval != null)
            {
                return(Created(Request.Path, _listItemServices.Update(value.ToDomainModel()).ToApiModel()));
            }

            return(NotFound());
        }