Exemple #1
0
        public async Task <IActionResult> PutTodoNote([FromRoute] int id, [FromBody] TodoNote todoNote)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != todoNote.Id)
            {
                return(BadRequest());
            }

            _context.Entry(todoNote).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TodoNoteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <int> Create(TagDAO data)
        {
            TagDAO addedTag = _context.Tags.Add(data).Entity;
            await _context.SaveChangesAsync();

            return(addedTag.Id);
        }
 public async Task Create(int todoItemId, List <int> tagIdList)
 {
     tagIdList.ForEach(tagId => _context.ItemTags.Add(new ItemTagDAO {
         TodoItemId = todoItemId, TagId = tagId
     }));
     await _context.SaveChangesAsync();
 }
Exemple #4
0
        public async Task <IActionResult> Create([Bind("Id,Title,Content")] Todo todo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(todo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(todo));
        }
        public async Task <int> Create(CategoryDAO data)
        {
            if (data.Name.Length <= 2)
            {
                throw new ArgumentException("Category name must be longer than 2 letters");
            }
            _context.Categories.Add(data);
            await _context.SaveChangesAsync();

            return(data.Id);
        }
Exemple #6
0
        public async Task <Board> AddBoard(Board board)
        {
            var newBoard = new Board
            {
                Name        = board.Name,
                Description = board.Description,
                CreatorId   = board.CreatorId
            };

            _db.Add(newBoard);

            await _db.SaveChangesAsync();

            return(newBoard);
        }
Exemple #7
0
        public async Task <Record> AddRecord(RecordDTO record, int boardId)
        {
            var newRecord = new Record
            {
                Name         = record.Name,
                Description  = record.Description,
                BoardId      = boardId,
                CreationDate = DateTimeOffset.Now,
                EndDate      = record.EndDate, // "0001-01-01T00:00:00+00:00" returns
                CreatorId    = 1               // fix to current user id
            };

            _db.Add(newRecord);

            await _db.SaveChangesAsync();

            return(newRecord);
        }
        public async Task <int> Create(TodoItemDAO data)
        {
            data.CreationDate = DateTime.UtcNow;
            if (data.CreationDate >= data.DeadLineDate)
            {
                throw new ArgumentException("Deadline date must be after the creation date");
            }
            if (await IsDuplicate(data))
            {
                throw new ArgumentException(String.Format("Item with the name {0} already exists", data.Name));
            }
            if (data.Priority > 5 || data.Priority < 1)
            {
                throw new ArgumentException("Priority value falls out of 1 to 5 range");
            }
            _context.TodoItems.Add(data);
            await _context.SaveChangesAsync();

            return(data.Id);
        }