示例#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));
        }
示例#2
0
        private async Task PersistTodoItem(TodoItemCreateFields fields)
        {
            var item = new TodoItem(fields.TodoListId, fields.ResponsiblePartyId, fields.Title, fields.Importance);

            await dbContext.AddAsync(item);

            await dbContext.SaveChangesAsync();
        }
        /// <inheritdoc/>
        public async Task <int> CreateAsync(TodoItemCreateFields create)
        {
            var item = new TodoItem(create.TodoListId, create.ResponsiblePartyId, create.Title, create.Importance);
            EntityEntry <TodoItem> entity = await _dbContext.AddAsync(item);

            await _dbContext.SaveChangesAsync();

            return(entity.Entity.TodoItemId);
        }
示例#4
0
 public TodoListDetailViewmodel(int todoListId, string title, ICollection <TodoItemSummaryViewmodel> items)
 {
     Items         = items;
     TodoListId    = todoListId;
     Title         = title;
     CreateNewItem = new TodoItemCreateFields {
         TodoListId = todoListId, TodoListTitle = title
     };
 }
示例#5
0
        public async Task <int> CreateAsync(TodoItemCreateFields fields)
        {
            var item = new TodoItem(fields.TodoListId, fields.ResponsiblePartyId, fields.Title, fields.Importance, fields.Rank);

            await _dbContext.AddAsync(item);

            await _dbContext.SaveChangesAsync();

            return(item.TodoItemId);
        }
示例#6
0
        public async Task <IActionResult> CreateTodoItem([FromBody] TodoItemCreateFields fields)
        {
            var item = new TodoItem(fields.TodoListId, fields.ResponsiblePartyId, fields.Title, fields.Importance);

            await dbContext.AddAsync(item);

            await dbContext.SaveChangesAsync();

            return(Ok());
        }
示例#7
0
        public async Task <IActionResult> HandleCreateForm(TodoItemCreateFields fields)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("_CreateFieldsPartial", fields));
            }

            await PersistTodoItem(fields);

            return(StatusCode(StatusCodes.Status201Created));
        }
示例#8
0
        public async Task <IActionResult> Create(TodoItemCreateFields fields)
        {
            if (!ModelState.IsValid)
            {
                return(View(fields));
            }

            await PersistTodoItem(fields);

            return(RedirectToListDetail(fields.TodoListId));
        }
        public async Task <IActionResult> CreateItem(TodoItemCreateFields fields)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            int id = await _todoItemRepository.CreateAsync(fields);

            return(Ok(id));
        }
        public async Task <IActionResult> Create(TodoItemCreateFields fields)
        {
            if (!ModelState.IsValid)
            {
                return(View(fields));
            }

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

            await dbContext.AddAsync(item);

            await dbContext.SaveChangesAsync();

            return(RedirectToListDetail(fields.TodoListId));
        }
        public async Task <IActionResult> CreatePartial(TodoItemCreateFields fields)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("_CreatePartial", fields));
            }

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

            await dbContext.AddAsync(item);

            await dbContext.SaveChangesAsync();

            return(PartialView("_EmptyPartial"));
        }
        public async Task <IActionResult> Create(TodoItemCreateFields fields)
        {
            if (!ModelState.IsValid)
            {
                return(View(fields));
            }
            int newRank = dbContext.TodoItems.Where(i => i.TodoListId == fields.TodoListId).Count() + 1;

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

            await dbContext.AddAsync(item);

            await dbContext.SaveChangesAsync();

            return(RedirectToListDetail(fields.TodoListId));
        }
 public async Task <int> Create([FromBody] TodoItemCreateFields fields) => await _itemService.CreateAsync(fields);
示例#14
0
        public WhenTodoItemIsCreated()
        {
            srcTodoList = new TestTodoListBuilder(new IdentityUser("*****@*****.**"), "shopping").Build();

            resultFields = TodoItemCreateFieldsFactory.Create(srcTodoList, srcTodoList.Owner.Id);
        }