コード例 #1
0
        public IActionResult GetPomodoroForTodo(Guid id)
        {
            var pomodors = _dbContext.PomodoroItems
                           .Include(n => n.ToDoItem)
                           .Where(n => n.ToDoItem != null && n.ToDoItem.Id == id);

            List <PomodoroItemModel> retVal = new List <PomodoroItemModel>();

            foreach (var item in pomodors)
            {
                retVal.Add(PomodoroConverter.FromEntityToModel(item));
            }

            return(Ok(retVal));
        }
コード例 #2
0
        public IActionResult Post([FromBody] PomodoroItemModel newItem)
        {
            logger.LogInformation("New promodo Item added");

            try
            {
                var newEntity = PomodoroConverter.FromModelToEntity(newItem);
                newEntity.ToDoItem = _dbContext.ToDoItems.Where(n => n.Id == newItem.ToDoItemGuid).FirstOrDefault();
                var dbEntity = _dbContext.PomodoroItems.Add(newEntity);
                _dbContext.SaveChanges();

                var savedItemModel = PomodoroConverter.FromEntityToModel(dbEntity.Entity);
                savedItemModel.ToDoItemGuid = newItem.ToDoItemGuid;
                logger.LogInformation($"added new {nameof(PomodoroItemModel)}");
                return(Ok(savedItemModel));
            }
            catch (Exception e)
            {
                logger.LogWarning($"Failed adding {nameof(PomodoroItemModel)}, {e?.GetType()}, msg: {e?.Message}");
                return(BadRequest($"Failed adding new {nameof(PomodoroItemModel)}"));
            }
        }