Пример #1
0
        public virtual async Task <ToDoItemDto> UpdateToDoItem(Guid key, ToDoItemDto toDoItem, CancellationToken cancellationToken)
        {
            if (toDoItem == null)
            {
                throw new BadRequestException("ToDoItemCouldNotBeNull");
            }

            Guid userId = Guid.Parse(UserInformationProvider.GetCurrentUserId());

            ToDoItem toDoItemToBeModified = await ToDoItemsRepository.GetByIdAsync(cancellationToken, key);

            if (toDoItemToBeModified == null)
            {
                throw new ResourceNotFoundException("ToDoItemCouldNotBeFound");
            }

            ToDoItemOptions toDoItemOptionsToBeModified = await ToDoItemOptionsListRepository.GetAll()
                                                          .FirstAsync(tdio => tdio.UserId == userId && tdio.ToDoItemId == key, cancellationToken);

            if (toDoItemOptionsToBeModified == null)
            {
                throw new ResourceNotFoundException("ToDoItemCouldNotBeFound");
            }

            if (toDoItem.ToDoGroupId != toDoItemToBeModified.ToDoGroupId)
            {
                throw new BadRequestException("ChangingToDoGroupIdIsNotSupportedAtTheMoment");
            }

            toDoItemToBeModified.Title       = toDoItem.Title;
            toDoItemToBeModified.IsImportant = toDoItem.IsImportant;
            toDoItemToBeModified.Notes       = toDoItem.Notes;
            toDoItemToBeModified.DueDate     = toDoItem.DueDate;

            toDoItemToBeModified.ModifiedOn = DateTimeProvider.GetCurrentUtcDateTime();

            if (toDoItemToBeModified.IsCompleted == false && toDoItem.IsCompleted == true)
            {
                toDoItemToBeModified.IsCompleted   = true;
                toDoItemToBeModified.CompletedById = userId;
            }
            else if (toDoItemToBeModified.IsCompleted == true && toDoItem.IsCompleted == false)
            {
                toDoItemToBeModified.IsCompleted   = false;
                toDoItemToBeModified.CompletedById = null;
            }

            toDoItemOptionsToBeModified.RemindOn      = toDoItem.RemindOn;
            toDoItemOptionsToBeModified.ShowInMyDayOn = toDoItem.ShowInMyDay == true ? (DateTimeOffset?)DateTimeProvider.GetCurrentUtcDateTime() : null;

            await ToDoItemsRepository.UpdateAsync(toDoItemToBeModified, cancellationToken);

            await ToDoItemOptionsListRepository.UpdateAsync(toDoItemOptionsToBeModified, cancellationToken);

            return(await GetMyToDoItems()
                   .FirstAsync(tdi => tdi.Id == key, cancellationToken));
        }
Пример #2
0
        public virtual IQueryable <ToDoItemDto> GetMyToDoItems()
        {
            Guid userId = Guid.Parse(UserInformationProvider.GetCurrentUserId());

            return(ToDoItemOptionsListRepository.GetAll().Where(tdio => tdio.UserId == userId)
                   .Select(tdio => new ToDoItemDto
            {
                Id = tdio.ToDoItem.Id,
                CreatedOn = tdio.ToDoItem.CreatedOn,
                ModifiedOn = tdio.ToDoItem.ModifiedOn,
                Title = tdio.ToDoItem.Title,
                RemindOn = tdio.RemindOn,
                CompletedBy = tdio.ToDoItem.CompletedBy.UserName,
                CreatedBy = tdio.ToDoItem.CreatedBy.UserName,
                DueDate = tdio.ToDoItem.DueDate,
                IsCompleted = tdio.ToDoItem.IsCompleted,
                IsImportant = tdio.ToDoItem.IsImportant,
                Notes = tdio.ToDoItem.Notes,
                ShowInMyDay = tdio.ShowInMyDayOn.Value.Date == DateTimeProvider.GetCurrentUtcDateTime().Date,
                ToDoGroupId = tdio.ToDoItem.ToDoGroupId,
                ToDoItemStepsCount = tdio.ToDoItem.Steps.Count(),
                ToDoItemStepsCompletedCount = tdio.ToDoItem.Steps.Count(s => s.IsCompleted == true),
            }));
        }