Esempio n. 1
0
        public MessageDto UpdateTodo(int id, TodoUpdateModel value)
        {
            MessageDto response = new MessageDto();

            TodoModelDto model = _lstTodo.FirstOrDefault(x => x.Id == id);

            if (model == null)
            {
                response.IsSuccess     = false;
                response.ReturnMessage = "Todo item not found";
                return(response);
            }

            model.Description = value.Description;
            model.IsCompleted = value.IsCompleted;

            int index = _lstTodo.FindIndex(x => x.Id == id);

            _lstTodo[index] = model;

            response.IsSuccess     = true;
            response.ReturnMessage = "Todo item updated successfully.";

            return(response);
        }
Esempio n. 2
0
        public IActionResult Put(long id, [FromBody] TodoUpdateModel todo)
        {
            if (todo == null)
            {
                return(BadRequest("Todo is null."));
            }
            Todo.Domain.Todo todoToUpdate = _dataService.Get(id);
            if (todoToUpdate == null)
            {
                return(NotFound("The Todo record couldn't be found."));
            }

            var user = _userDataService.GetByEmail(User.Identity.Name);

            if (_userDataService.CanUserManageTodo(user, todoToUpdate))
            {
                _dataService.Update(todoToUpdate, new Todo.Domain.Todo {
                    Text = todo.Text, IsDone = todo.IsDone
                });
                return(NoContent());
            }
            else
            {
                return(Unauthorized());
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var todo = await _context.Todos
                       .Include(x => x.PersonInCharge)
                       .Include(x => x.Participants)
                       .SingleOrDefaultAsync(x => x.Id == id);

            if (todo == null)
            {
                return(NotFound());
            }

            var users = await _userServices.GetAllUsers();

            var userIdsInTodo  = todo.Participants.Select(x => x.UserId);
            var usersInTodo    = users.Where(x => userIdsInTodo.Contains(x.Id));
            var usersNotInTodo = users.Except(usersInTodo);

            TodoUpdateModel updateModel = new TodoUpdateModel
            {
                TodoId         = todo.Id,
                TodoInfo       = _mapper.Map <TodoInfoEditModel>(todo),
                AllUsers       = _mapper.Map <List <UserViewModel> >(users),
                Participants   = _mapper.Map <List <UserViewModel> >(usersInTodo),
                UsersNotInTodo = _mapper.Map <List <UserViewModel> >(usersNotInTodo)
            };

            return(View(updateModel));
        }
        /// <inheritdoc />
        public async Task <Guid> Update(TodoUpdateModel todoEditItem)
        {
            var todoItem = await _context.TodoItems.FirstOrDefaultAsync(a => a.Guid == todoEditItem.Guid);

            todoItem.Name       = todoEditItem.Name;
            todoItem.IsComplete = todoEditItem.IsComplete;
            _context.TodoItems.Update(todoItem);
            await _context.SaveChangesAsync();

            return(todoItem.Guid);
        }
Esempio n. 5
0
        public async Task <IActionResult> Update(string id, TodoUpdateModel todoIn)
        {
            var todo = await _service.Get(id);

            if (todo == null)
            {
                return(NotFound());
            }

            _service.Update(id, todoIn);

            return(Ok(todoIn));
        }
Esempio n. 6
0
        public async Task <IActionResult> Edit(int id, TodoUpdateModel updateModel)
        {
            var todo = await _context.Todos
                       .SingleOrDefaultAsync(x => x.Id == id);

            if (todo == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                ApplicationUser currentUser = await _userManager.GetUserAsync(User);

                /** Only allow task owner and boss can edit task */
                if (todo.PersonInChargeId != currentUser.Id)
                {
                    if (!User.IsInRole(RoleNameEnum.Boss))
                    {
                        return(Forbid());
                    }
                }
                await _todoServices.UpdateTodo(updateModel.TodoInfo, todo, currentUser, _context);

                return(RedirectToAction(nameof(Inbox)));
            }

            /** Prepare info for edit page when update process is failed */
            var participants = await _context.Participants
                               .Where(x => x.TodoId == todo.Id)
                               .ToListAsync();

            var users = await _userServices.GetAllUsers();

            var userIdsInTodo  = participants.Select(x => x.UserId);
            var usersInTodo    = users.Where(x => userIdsInTodo.Contains(x.Id));
            var usersNotInTodo = users.Except(usersInTodo);

            updateModel.TodoId         = todo.Id;
            updateModel.AllUsers       = _mapper.Map <List <UserViewModel> >(users);
            updateModel.UsersNotInTodo = _mapper.Map <List <UserViewModel> >(usersInTodo);
            updateModel.Participants   = _mapper.Map <List <UserViewModel> >(usersNotInTodo);
            return(View(updateModel));
        }
Esempio n. 7
0
 public async Task <Guid> PutTodoItem([FromBody] TodoUpdateModel todoItem)
 {
     return(await _todoService.Update(todoItem));
 }
Esempio n. 8
0
 public IActionResult Put(int id, [FromBody] TodoUpdateModel value)
 {
     return(this.Ok(_todoService.UpdateTodo(id, value)));
 }
Esempio n. 9
0
        /// <summary>
        /// update TODO
        /// </summary>
        /// <param name="id"></param>
        /// <param name="todoIn"></param>
        public void Update(string id, TodoUpdateModel todoIn)
        {
            var todo = _mapper.Map <Todo>(todoIn);

            _todo.ReplaceOne(t => t.Id == id, todo);
        }