Beispiel #1
0
        public async Task <ToDoItemDetail> CreateAsync(ToDoItemDetail item)
        {
            var plan = await _db.Plans.FindAsync(item.PlanId);

            if (plan == null)
            {
                throw new NotFoundException($"Plan with the {item.PlanId} couldn't be found");
            }

            var todoItem = new ToDoItem
            {
                EstimatedDate = item.EstimationDate,
                CreatedDate   = DateTime.UtcNow,
                Description   = item.Description,
                Id            = Guid.NewGuid().ToString(),
                IsDeleted     = false,
                IsDone        = false,
                Plan          = plan,
                UserId        = _identity.UserId,
                ModifiedDate  = DateTime.UtcNow,
            };
            await _db.ToDoItems.AddAsync(todoItem);

            await _db.SaveChangesAsync();

            return(todoItem.ToToDoItemDetail());
        }