Example #1
0
        public async Task <ToDoItem> UpdateAsync(string id, ToDoItemUpdate updateModel)
        {
            var item = _items.FindAsync(i => i.Id == id).Result.FirstOrDefault();

            if (item != null)
            {
                if (!string.IsNullOrEmpty(updateModel.Description))
                {
                    item.Description = updateModel.Description;
                }

                if (updateModel.Favorite != null)
                {
                    item.Favorite = updateModel.Favorite.Value;
                }

                if (updateModel.Done != null)
                {
                    item.Done = updateModel.Done.Value;
                }

                _items.FindOneAndReplace(i => i.Id == item.Id, item);

                return(item);
            }
            return(null);
        }
Example #2
0
        public async Task <ActionResult <ToDoItem> > UpdateAsync(
            [Required] string id, [Required] ToDoItemUpdate updateModel)
        {
            //check id
            if (string.IsNullOrEmpty(id))
            {
                return(BadRequest(new Dictionary <string, string>()
                {
                    { "message", "Id is required" }
                }));
            }

            var modelInDb = await _repository.GetAsync(id);

            if (modelInDb == null)
            {
                return(NotFound(new Dictionary <string, string>()
                {
                    { "message", $"Can't find {id}" }
                }));
            }

            //update
            var updated = await _repository.UpdateAsync(id, updateModel);

            return(Ok(updated));
        }
Example #3
0
        public async Task <ToDoItem> UpdateAsync(string id, ToDoItemUpdate updateModel)
        {
            if (_dic.TryGetValue(id, out var item))
            {
                if (!string.IsNullOrEmpty(updateModel.Description))
                {
                    item.Description = updateModel.Description;
                }

                if (updateModel.Favorite != null)
                {
                    item.Favorite = updateModel.Favorite.Value;
                }

                if (updateModel.Done != null)
                {
                    item.Done = updateModel.Done.Value;
                }

                return(item);
            }
            return(null);
        }
 public Task <ToDoItem> UpdateAsync(string id, ToDoItemUpdate updateModel)
 {
     throw new NotImplementedException();
 }