示例#1
0
        public async Task <IActionResult> Create([FromBody] IdeaViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var session = await _sessionRepository.GetByIdAsync(model.SessionId);

            if (session == null)
            {
                return(NotFound(model.SessionId));
            }

            var idea = new Idea()
            {
                DateCreated = DateTimeOffset.Now,
                Description = model.Description,
                Name        = model.Name
            };

            session.AddIdea(idea);

            await _sessionRepository.UpdateAsync(session);

            return(Ok(session));
        }
示例#2
0
        public async Task <IActionResult> Create([FromBody] NewIdeaModel model)
        {
            if (!ModelState.IsValid)
            {
                Logger.Error($"Passed model is not valid: {model}");
                return(BadRequest(ModelState));
            }

            var session = await _sessionRepository.GetByIdAsync(model.SessionId);

            if (session == null)
            {
                Logger.Warn($"Session with id: {model.SessionId} is not found");
                return(NotFound(model.SessionId));
            }

            var idea = new Idea()
            {
                DateCreated = DateTimeOffset.Now,
                Description = model.Description,
                Name        = model.Name
            };

            session.AddIdea(idea);

            await _sessionRepository.UpdateAsync(session);

            return(Ok(session));
        }
示例#3
0
        public async Task <IActionResult> Create([FromBody] NewIdeaModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var session = await _sessionRepository.GetByIdAsync(model.SessionId);

            if (session == null)
            {
                if (Logger.useLogs)
                {
                    Logger.Log.Error("Session not found");
                }
                return(NotFound(model.SessionId));
            }

            var idea = new Idea()
            {
                DateCreated = DateTimeOffset.Now,
                Description = model.Description,
                Name        = model.Name
            };

            session.AddIdea(idea);

            Logger.Log.Debug($"idea.DateCreated: {idea.DateCreated} idea.Name: {idea.Name} idea.Id: {idea.Id}");

            await _sessionRepository.UpdateAsync(session);

            return(Ok(session));
        }