示例#1
0
        public IActionResult Create([FromBody] ActionItemDto dto)
        {
            DateTime tempdt;
            var      entry = new ActionItemModel
            {
                UserId      = dto.UserId,
                DueDate     = DateTime.TryParse(dto.DueDate, out tempdt) ? (DateTime?)tempdt : null,
                Modified    = DateTime.Now,
                Description = dto.Description,
                Tags        = dto.Tags ?? "",
                State       = dto.State == 0 ? ActionItemState.NotStarted : (ActionItemState)dto.State
            };

            try
            {
                _context.ActionItems.Add(entry);
                _context.SaveChanges();
                return(CreatedAtRoute("GetActionItem", new { id = entry.Id }, entry));
            }
            catch
            {
                Console.WriteLine("error");
                throw;
            }
        }
示例#2
0
        public async Task <ActionResult> UpdateActionItem(long id, [FromBody] ActionItemDto dto)
        {
            try
            {
                DateTime tempdt;
                var      entry = await _context.ActionItems.FindAsync(id);

                entry.Description = dto.Description ?? entry.Description;
                entry.DueDate     = DateTime.TryParse(dto.DueDate, out tempdt) ? (DateTime?)tempdt : entry.DueDate;
                entry.Tags        = dto.Tags ?? entry.Tags;
                _context.SaveChanges();
                return(CreatedAtRoute("GetActionItem", new { id = entry.Id }, entry));
            }
            catch
            {
                Console.WriteLine("error");
                throw;
            }
        }