Ejemplo n.º 1
0
        public async Task <IActionResult> AddNewListItem([FromBody] TodoItemCreateFields fields)
        {
            var todoList = await dbContext.TodoLists.FirstOrDefaultAsync(list => list.TodoListId == fields.TodoListId);

            if (todoList == null)
            {
                ModelState.AddModelError(nameof(fields.TodoListId), "Todo List does not exist");
            }

            var responsibleParty = await dbContext.Users.FirstOrDefaultAsync(user => user.Id == fields.ResponsiblePartyId);

            if (responsibleParty == null)
            {
                ModelState.AddModelError(nameof(fields.ResponsiblePartyId), "Responsible party does not exist");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var item = new TodoItem(fields.TodoListId, fields.ResponsiblePartyId, fields.Title, fields.Importance);

            todoList.Items.Add(item);
            await dbContext.SaveChangesAsync();

            var viewModel = TodoItemSummaryViewmodelFactory.Create(item);

            viewModel.ResponsibleParty.FullName = await gravatarService.GetUserFullName(viewModel.ResponsibleParty.Email);

            return(Ok(viewModel));
        }
Ejemplo n.º 2
0
        public WhenTodoItemIsConvertedToSummaryView()
        {
            var todoList = new TestTodoListBuilder(new IdentityUser("*****@*****.**"), "shopping")
                           .WithItem("bread", Importance.High)
                           .Build()
            ;

            srcTodoItem = todoList.Items.First();

            //change IsDone to true because default is false.
            srcTodoItem.IsDone           = true;
            srcTodoItem.ResponsibleParty = todoList.Owner;

            resultFields = TodoItemSummaryViewmodelFactory.Create(srcTodoItem);
        }
Ejemplo n.º 3
0
        public static IEnumerable <object[]> Data()
        {
            var breadItem = todoList.Items.Single(item => item.Title == "bread");
            var bread     = TodoItemSummaryViewmodelFactory.Create(breadItem);

            var irnbruItem = todoList.Items.Single(item => item.Title == "Irn-Bru");
            var irnBru     = TodoItemSummaryViewmodelFactory.Create(irnbruItem);

            var sortedByImportance = new List <TodoItemSummaryViewmodel> {
                bread, irnBru
            };
            var sortedByRank = new List <TodoItemSummaryViewmodel> {
                irnBru, bread
            };

            return(new List <object[]>
            {
                new object[] { null, sortedByImportance },
                new object[] { SortOrder.Importance, sortedByImportance },
                new object[] { SortOrder.Rank, sortedByRank },
            });
        }