/// <summary>
        /// This is the basic update of direct incident fields
        /// Collections are handled in their own objectsd
        /// </summary>
        /// <param name="incident"></param>
        /// <returns></returns>
        public async Task <BaseIncident> Update(BaseIncident incident)
        {
            var dbItem = this.ctx.Incidents.Find(incident.CommonId);

            if (dbItem == null)
            {
                throw new NullReferenceException("No incident was found");
            }
            if (dbItem.IncidentStatusId == (int)IncidentStatusTypes.Closed)
            {
                throw new ArgumentOutOfRangeException("Cannot update a closed incident!");
            }

            // Logical changes.
            // Mark some differences since last update


            // Have we changed to Status.unassigned? if so ensure we remove the lead officer.
            if (dbItem.IncidentStatusId == (int)IncidentStatusTypes.Open && incident.StatusId == (int)IncidentStatusTypes.Unassigned)
            {
                incident = incident.WithLeadOfficer("");
            }

            // Have we assigned a new lead officer?
            // so status must be set to open
            if (String.IsNullOrEmpty(dbItem.LeadOfficer) && !String.IsNullOrEmpty(incident.LeadOfficer) && incident.StatusId != (int)IncidentStatusTypes.Closed)
            {
                incident = incident.WithStatus((int)IncidentStatusTypes.Open);
            }

            //Transfer our updates into the existing incident
            //incident.ToUpdateDb(dbItem);
            var receivedOn = dbItem.ReceivedOn;

            mapper.Map(incident, dbItem);
            // This can be cleared out by faulty data from the client.
            // It should not be replaced once set.
            //if (receivedOn.HasValue)
            //    dbItem.ReceivedOn = receivedOn;


            // Are we closed?
            // Then ensure we update the closed date.
            if (dbItem.IncidentStatusId == (int)IncidentStatusTypes.Closed)
            {
                dbItem.IncidentClosed = DateTime.UtcNow;
            }

            var updatedDbItem = this.ctx.Incidents.Update(dbItem);

            await this.ctx.SaveChangesAsync();

            return(mapper.Map <IncidentDb, BaseIncident>(updatedDbItem.Entity));
        }
        public async Task <BaseIncident> Add(BaseIncident incident)
        {
            //if (incident.CommonId != 0) throw new IncidentExistsException("This item has already been added.");
            var dbItem = mapper.Map <BaseIncident, IncidentDb>(incident);

            dbItem.IncidentCreated = dbItem.Created;
            dbItem.IncidentClosed  = null; // Ensure lack of shenanigans
            var dbPonder = this.ctx.Incidents.Add(dbItem);

            await this.ctx.SaveChangesAsync();

            return(mapper.Map <IncidentDb, BaseIncident>(dbPonder.Entity));
        }
Beispiel #3
0
        public async Task UpdateIncidentSetFbo()
        {
            using (var ctx = SeedingConfigData.GetDbContext(this.conn))
            {
                var simsHost = SimsDbHost.CreateHost(ctx, this.mapper, this.userId);

                BaseIncident incident = await simsHost.Incidents.Get(22);

                // Ensure we have a lead officer and we are open
                var changedIncident = incident
                                      .WithPrincipalFbo(16);
                var updateIncident = await simsHost.Incidents.Update(changedIncident);

                Assert.True(updateIncident.PrincipalFBOId == 16);
            }
        }
        public Task <BaseIncident> Add(BaseIncident incident)
        {
            if (incident.CommonId != 0)
            {
                throw new SimsIncidentExistsException("This incident has already been added.");
            }

            // IF we have an officer, and status is not open...
            if (!String.IsNullOrEmpty(incident.LeadOfficer) && incident.StatusId != (int)SimsIncidentStatusTypes.Open)
            {
                incident = incident.WithStatus((int)SimsIncidentStatusTypes.Open);
            }
            // if we don't have an officer status must be unsassigned
            if (String.IsNullOrEmpty(incident.LeadOfficer))
            {
                incident = incident.WithStatus((int)SimsIncidentStatusTypes.Unassigned);
            }
            return(dbHost.Incidents.Add(incident));
        }
 public async Task <BaseIncident> Update(BaseIncident incident)
 {
     try
     {
         if (incident.CommonId == 0)
         {
             throw new SimsItemMissing("Incident Id missing");
         }
         return(await dbHost.Incidents.Update(incident.SignalStatusId == 0?incident.WithSignalStatusId(null) : incident));
     }
     catch (NullReferenceException)
     {
         throw new SimsIncidentMissingException("Incident missing");
     }
     catch (ArgumentOutOfRangeException)
     {
         throw new SimsIncidentClosedException("Cannot update closed incident");
     }
 }
Beispiel #6
0
        public async Task AddIncidentLeadOfficer()
        {
            var incident = new BaseIncident(
                incidentTitle: "New Incident (Lead officer)",
                incidentTypeId: 36,
                incidentSourceId: 4,
                contactMethodId: 2,
                statusId: (int)SimsIncidentStatusTypes.Unassigned,
                priorityId: 2,
                classificationId: 1,
                dataSourceId: 9,
                oimtGroups: "OimtGroups, OimitGroups 2",
                signalUrl: "",
                productTypeId: 3,
                leadOfficer: this.userId3,
                adminLeadId: 1,
                leadOffice: "",
                fieldOfficer: "",
                lAAdvised: false,
                onlineFormId: null,
                deathIllnessId: 3,
                receivedOn: null,
                incidentCreated: DateTime.Now,
                lastChangedBy: this.miller,
                lastChangedDate: DateTime.Now,
                signalStatusId: null,
                notifierId: null,
                sensitiveInfo: false,

                principalFBOId: null,
                leadLocalAuthorityId: null,
                incidentClosed: null
                );

            using (var ctx = SeedingConfigData.GetDbContext(this.conn))
            {
                var simsHost      = SimsDbHost.CreateHost(ctx, this.mapper, this.userId);
                var savedIncident = await simsHost.Incidents.Add(incident);

                Assert.True(savedIncident.MostUniqueId != Guid.Empty);
            }
        }