Beispiel #1
0
        public IActionResult Add([FromBody] TalkCreateDto talkCreateDto)
        {
            if (talkCreateDto == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Talk toAdd = AutoMapper.Mapper.Map <Talk>(talkCreateDto);

            toAdd.Added      = DateTime.UtcNow;
            toAdd.TimerTicks = new List <TimerTick>();
            toAdd.UserId     = User.Identity.Name;
            _talksRepository.Add(toAdd);

            if (!_talksRepository.Save())
            {
                throw new Exception("Creating an item failed on save.");
            }

            Talk newItem = _talksRepository.GetSingle(toAdd.Id, User.Identity.Name);

            return(CreatedAtRoute(nameof(GetSingle), new { id = newItem.Id },
                                  AutoMapper.Mapper.Map <TalkDto>(newItem)));
        }
Beispiel #2
0
 public void Save()
 {
     talksRepository.Save();
 }