Example #1
0
        public async Task <IActionResult> SaveSettingAsync([FromBody] CreateSetting command)
        {
            await rules
            .RequireSettingNameOrFacilityId()
            .Apply(command, ModelState);

            if (ModelState.IsValid)
            {
                int settingId = await service.Execute(command);

                var uri = Url.Action("Get", new { id = settingId });

                return(Created(uri, new OutbreakSettingInformationDTO
                {
                    Id = settingId,
                    Address = command.Address,
                    IsPrimary = command.IsPrimary,
                    OtherType = command.OtherType,
                    SettingContact = command.SettingContact,
                    SettingContactPhone = command.SettingContactPhone,
                    SettingName = command.SettingName,
                    SettingType = command.SettingType
                }));
            }

            return(BadRequest(ModelState));
        }
        private async Task SaveSetting(CreateSetting command, Data.Outbreak outbreak, OutbreakSettings setting)
        {
            //if new setting is primary; set all others to not primary
            if (command.IsPrimary)
            {
                foreach (var s in outbreak.OutbreakSettings)
                {
                    s.InPrimary = false;
                }
            }

            setting.IdOutbreak        = command.OutbreakId;
            setting.CdSetting         = command.SettingType;
            setting.InPrimary         = command.IsPrimary;
            setting.DsSettingOther    = command.OtherType;
            setting.IdResourceSetting = command.SettingFacilityId;
            setting.DsAddress         = command.Address.AddressLine1 ?? "";
            setting.DsAddress2        = command.Address.AddressLine2 ?? "";
            setting.DsCity            = command.Address.City ?? "";
            setting.DsZip             = command.Address.Zip ?? "";
            setting.CdState           = command.Address.State ?? "";
            setting.CdCountry         = command.Address.Country ?? "";
            setting.CdCounty          = command.Address.County ?? "";
            setting.DsContactPhn      = command.SettingContactPhone ?? "";
            setting.NmContact         = command.SettingContact ?? "";


            if (command.SettingFacilityId.HasValue)
            {
                var facility = await writeContext.ResourceSetting
                               .FindAsync(command.SettingFacilityId);

                setting.NmFacility = facility.NmSetting;
                setting.DsAddress  = facility.DsAddr1Name;
                setting.DsAddress2 = facility.DsAddr2;
                setting.DsCity     = facility.DsCity;
                setting.DsZip      = facility.DsZip;
                setting.CdCounty   = facility.CdCounty;
                setting.CdCountry  = facility.CdCountry;
            }

            //generate email alert on setting save
            var alerts = await writeContext.EpiUserAlerts
                         .Where(alert => alert.CdAlert == AlertType.Outbreak)
                         .Where(alert => alert.CdCounty == outbreak.CdCountyInitiating)
                         .Select(alert => new EmailQueue
            {
                IdUserRecipient = alert.IdUser,
                CdAlert         = alert.CdAlert,
                CdCounty        = alert.CdCounty,
                CdEntity        = AlertType.Outbreak,
                CdProcessed     = AlertStatus.NotSent,
                IdEntity        = outbreak.IdOutbreak.ToString()
            })
                         .ToListAsync();

            await emailService.DispatchAlerts(alerts);
        }
Example #3
0
        public override async Task HandleAsync(CreateDefaultsSettings command, ICorrelationContext context)
        {
            DefaultsSettings.Get.ForEach(async s =>
            {
                Setting setting = Mapper.Map <Setting>(s);

                CreateSetting cmd = Mapper.Map <CreateSetting>(setting);

                await BusPublisher.SendAsync(cmd, context);
            });
        }
Example #4
0
 public IActionResult Get(CreateSetting model)
 {
     try
     {
         return(Json(_settingService.GetAllSettings(model.ApplicationName, name: model.Name, cache: true)));
     }
     catch (Exception)
     {
         return(Json(new BaseCommand()));
     }
 }
Example #5
0
        public async Task <IActionResult> Post([FromBody] CreateSetting command)
        {
            var result = new BaseCommand();

            try
            {
                if (ModelState.IsValid)
                {
                    var setting = _mapper.Map <CreateSetting, Setting>(command);
                    setting.IsActive = true;
                    await _settingService.InsertSetting(setting);

                    return(Accepted());
                }
            }
            catch (Exception) { }
            return(Json(result));
        }
        //TODO:  this needs major work
        public async Task <int> Execute(CreateSetting command)
        {
            var outbreak = await writeContext.Outbreak
                           .Include(o => o.OutbreakSettings)
                           .FirstOrDefaultAsync(o => o.IdOutbreak == command.OutbreakId);

            OutbreakSettings setting = new OutbreakSettings();

            setting.IdSetting = (short)await sequenceGenerator.GetNextAsync(SequenceType.OutbreakSettings);

            await SaveSetting(command, outbreak, setting);

            outbreak.OutbreakSettings.Add(setting);

            await writeContext.SaveChangesAsync();

            return(setting.IdSetting);
        }
Example #7
0
        public async Task <IActionResult> Post([FromBody] CreateSetting command)
        {
            await BusClient.PublishAsync(command);

            return(Accepted());
        }
Example #8
0
 public async Task <IActionResult> Post(CreateSetting command)
 => await SendAsync(command.BindId(c => c.Id),
                    resourceId : command.Id, resource : "settings");