示例#1
0
        public async Task <IActionResult> Put([FromBody] BulletinDto bulletinDto)
        {
            var bulletin = Mapper.Map <Bulletin>(bulletinDto);
            await Executor.GetCommand <UpdateBulletinCommand>().Process(c => c.ExecuteAsync(bulletin));

            return(NoContent());
        }
示例#2
0
        public IActionResult RemoveBulletin(int id)
        {
            Bulletin bulletinToRemove = _bulletinManager.GetBulletin(id);

            Bulletin    removedBulletin    = _bulletinManager.RemoveBulletin(bulletinToRemove);
            BulletinDto removedBulletinDto = _mapper.Map <BulletinDto>(removedBulletin);

            return(Ok(removedBulletinDto));
        }
示例#3
0
        public async Task <IActionResult> Post([FromBody] BulletinDto bulletinDto)
        {
            var bulletin = Mapper.Map <Bulletin>(bulletinDto);

            Executor.GetHandler <GenerateBulletinNumberHandler>()
            .Process <string>(h => h.Execute(bulletin));
            var bulletinId = await Executor.GetCommand <CreateBulletinCommand>().Process(c => c.ExecuteAsync(bulletin));

            return(Ok(bulletinId));
        }
示例#4
0
        public IActionResult NewBulletin([FromBody] BulletinDto bulletinDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Bulletin bulletin = _mapper.Map <Bulletin>(bulletinDto);

            Bulletin savedBulletin = _bulletinManager.SaveNewBulletin(bulletin, User);

            string url = Url.Action("GetBulletin", "Bulletin", new { id = bulletin.Id });

            BulletinDto savedBulletinDto = _mapper.Map <BulletinDto>(savedBulletin);

            return(Created(url, savedBulletinDto));
        }
示例#5
0
        public IActionResult ReplaceBulletin(int id, [FromBody] Bulletin bulletin)
        {
            Bulletin bulletinToReplace = _bulletinManager.GetBulletin(id);

            if (bulletinToReplace != null)
            {
                _bulletinManager.Detach(bulletinToReplace);
            }

            if (ModelState.IsValid && bulletinToReplace != null)
            {
                bulletinToReplace.Title   = bulletin.Title;
                bulletinToReplace.Content = bulletin.Content;

                Bulletin    bulletinReplaced    = _bulletinManager.ReplaceBulletin(bulletinToReplace);
                BulletinDto bulletinReplacedDto = _mapper.Map <BulletinDto>(bulletinReplaced);
                return(Ok(bulletinReplacedDto));
            }
            else
            {
                return(BadRequest());
            }
        }