public CreateResponse Create(WarningRequest request)
 {
     try
     {
         var warning = TypeAdapter.Adapt <Warning>(request);
         _warningValidator.ValidateAndThrowException(warning, "Base,Create");
         _warningRepository.Add(warning);
         return(new CreateResponse(warning.Id));
     }
     catch (DataAccessException)
     {
         throw new ApplicationException();
     }
 }
Beispiel #2
0
        public void AddWarning(int entityID, string message)
        {
            var warning = new Warning()
            {
                DateTime = DateTime.Now,
                Day      = GameHelper.CurrentDay,
                EntityID = entityID,
                Unread   = true,
                Message  = message
            };

            using (NoSaveChanges)
            {
                var entity = entityRepository.GetById(entityID);
                if (entity.GetEntityType() == EntityTypeEnum.Country)
                {
                    var countryLink      = EntityLinkCreator.Create(entity);
                    var presidentMessage = $"[Redirected from {countryLink}] {message}";
                    if (entity.Country.PresidentID.HasValue)
                    {
                        AddWarning(entity.Country.PresidentID.Value, presidentMessage);
                    }
                }
                else if (entity.GetEntityType() == EntityTypeEnum.Party)
                {
                    var president = entity.Party.GetPresident();
                    if (president != null)
                    {
                        var partyLink        = EntityLinkCreator.Create(entity);
                        var presidentMessage = $"[Redirected from {partyLink}] {message}";
                        AddWarning(president.CitizenID, presidentMessage);
                    }
                }
            }
            warningRepository.Add(warning);
            ConditionalSaveChanges(warningRepository);
        }
Beispiel #3
0
        public IActionResult Post([FromBody] Warning warning)
        {
            var newWarning = warningRepository.Add(warning);

            return(Created("api/warning", warning));
        }