Example #1
0
 protected async Task SetTodoStatus(TodoItemStatus status)
 {
     TodoItem.Status = TodoItem.Status == status ? TodoItemStatus.Open : status;
     if (EditContext.Validate())
     {
         await Save();
     }
 }
Example #2
0
 public void Update(string title, string content, TodoItemStatus status, List <string> tags)
 {
     Title   = title;
     Content = content;
     Status  = status;
     Tags    = tags;
     SetUpdated();
 }
Example #3
0
 private TodoItemStatusHistoryDataAccess MakeStatusHistory(string todoItemId, TodoItemStatus status, DateTime date)
 {
     return(_todoItemStatusHistoryService.Create(new TodoItemStatusHistoryDataAccess
     {
         TodoItemId = todoItemId,
         Status = status,
         CreatedDate = date,
         LastUpdatedDate = date
     }));
 }
        /// <summary>
        /// Adds the to-do itemDto to the db
        /// </summary>
        /// <param name="itemDto"></param>
        /// <returns></returns>
        public async Task <TodoItemDto> AddItemAsync(TodoItemDto itemDto)
        {
            Guard.NotNull(itemDto, nameof(itemDto));
            Guard.NotNull(itemDto.Description, nameof(itemDto.Description));

            _logger.LogInformation($"In {nameof(AddItemAsync)}");
            try
            {
                var todoItem = itemDto.ToEntity();

                //set create time to now
                todoItem.CreateDateTime = DateTime.UtcNow;
                var status = todoItem.StatusHistory.First();
                if (todoItem.StatusHistory == null || status == null)
                {
                    status = new TodoItemStatus {
                        Status = itemDto.CurrentStatus ?? StatusValues.New
                    };
                    todoItem.StatusHistory = new List <TodoItemStatus> {
                        status
                    };
                }

                status.StatusDateTime = todoItem.CreateDateTime;

                using (var context = TodoContextFactory.Create())
                {
                    var todoResult = await context.ToDoItems.AddAsync(todoItem);

                    await context.SaveChangesAsync();

                    itemDto.CreateDateTime = todoResult.Entity.CreateDateTime;
                    itemDto.ItemId         = todoResult.Entity.ItemId;

                    // set the status fields
                    status = todoResult.Entity.StatusHistory.First();
                    itemDto.CurrentStatus        = status.Status;
                    itemDto.LastModifiedDateTime = status.StatusDateTime;
                }

                return(itemDto);
            }
            catch (Exception)
            {
                //log error
                throw;
            }
            finally
            {
                _logger.LogInformation($"Out {nameof(AddItemAsync)}");
            }
        }
Example #5
0
        public IActionResult Patch(int id, TodoItemStatus status)
        {
            TodoItemDto currentItem = _dbContext.Tasks.Single(t => t.Id == id);

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

            currentItem.Status = status;

            return(Ok());
        }
        public async Task <TodoItemViewModel> ChangeStatus(long id, TodoItemStatus status)
        {
            var todoItemToChangeStatus = await GetTodoItemOfCurrentUserById(id);

            if (Enum.IsDefined(typeof(TodoItemStatus), status))
            {
                todoItemToChangeStatus.Status = status;
            }
            else
            {
                throw new Exception("Status not defined");
            }
            await _context.SaveChangesAsync();

            return(TransformToView(todoItemToChangeStatus));
        }
Example #7
0
        public static TodoItemDataAccess ToDataAccess(TodoItemCreate create, DateTime createdDate, TodoItemStatus status = TodoItemStatus.Pending)
        {
            if (create == null)
            {
                return(null);
            }

            return(new TodoItemDataAccess
            {
                Title = create.Title,
                Description = create.Description,
                Status = status,
                CreatedDate = createdDate,
                LastUpdatedDate = createdDate
            });
        }