public ActionResult <Hit> Create([FromBody] HitDto hitDto) { try { hitDto.HeroId = HeroService.GetLoggedInUserId(this); Hit hit = _service.Create(hitDto); return(Ok(hit)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public Hit Create(HitDto hitDto) { if (_dragons.Dragons.Get(hitDto.DragonId) == null) { throw new DragonNotExistsException(); } Dragon currentDragon = _dragons.Dragons.Get(hitDto.DragonId); if (DragonService.IsDragonDead(currentDragon)) { throw new DragonIsDeadException(); } Hit hit = new Hit(_heroes.Heroes.Get(hitDto.HeroId), ref currentDragon); _unitOfWork.Hits.Create(hit); _dragons.Save(); _unitOfWork.Save(); return(hit); }