Beispiel #1
0
        private CallHistory GenerateCall(IEnumerable <OnCallSlot> slots, Models.Incident incident)
        {
            var lastCall = incident.CallHistories.Where(y => !y.Ignore).LastOrDefault();

            if (lastCall == null)
            {
                return(new CallHistory
                {
                    IncidentId = incident.Id,
                    CreatedTime = DateTime.UtcNow,
                    UserId = slots.First().UserId,
                    Role = SlotRole.Primary
                });
            }
            else
            {
                var role = (int)slots.Single(x => x.UserId == lastCall.UserId).Role;
                role = (role + 1) % Enum.GetNames(typeof(SlotRole)).Length;
                return(new CallHistory
                {
                    IncidentId = incident.Id,
                    CreatedTime = DateTime.UtcNow,
                    UserId = slots.Single(x => x.Role == (SlotRole)role).UserId,
                    Role = (SlotRole)role
                });
            }
        }
Beispiel #2
0
        public Models.Incident Add(Models.Incident incident)
        {
            var modelCollection = projectDB.GetCollection("incidents");

            modelCollection.Insert(incident);

            return(incident);
        }
Beispiel #3
0
        public void PostShouldAddNewIncident()
        {
            var incident = new Models.Incident();
            var count    = _incidentRepository.GetAll().Incidents.Count;

            var controller = new IncidentController(_incidentRepository);
            var result     = controller.Post(incident);

            Assert.Equal(count + 1, _incidentRepository.GetAll().Incidents.Count);
        }
Beispiel #4
0
        public bool Update(Models.Incident incident)
        {
            var updateIncident = Get(incident.id);

            updateIncident.Agency      = incident.Agency;
            updateIncident.AlertLevel  = incident.AlertLevel;
            updateIncident.CouncilArea = incident.CouncilArea;
            updateIncident.Location    = incident.Location;
            updateIncident.Name        = incident.Name;
            updateIncident.Size        = incident.Size;
            updateIncident.Status      = incident.Status;
            return(true);
        }
Beispiel #5
0
        public bool Update(Models.Incident incident)
        {
            var incidents    = projectDB.GetCollection("incidents");
            var currIncident = incidents.FindOneById(ObjectId.Parse(incident.sId));

            currIncident["Name"]        = incident.Name;
            currIncident["AlertLevel"]  = incident.AlertLevel;
            currIncident["Location"]    = incident.Location;
            currIncident["CouncilArea"] = incident.CouncilArea;
            currIncident["Status"]      = incident.Status;
            currIncident["Type"]        = incident.Type;
            currIncident["Size"]        = incident.Size;
            currIncident["Agency"]      = incident.Agency;
            currIncident["Updated"]     = incident.Updated;

            incidents.Save(currIncident);
            return(true);
        }
        public async Task <IActionResult> Put(string title, string body, int severity, Guid projectId, string secret)
        {
            if (!await DB.Projects.AnyAsync(x => x.Id == projectId && x.Secret == secret))
            {
                return(Json(new { code = 403, msg = "项目ID或Secret不正确" }));
            }

            var project = await DB.Projects.SingleAsync(x => x.Id == projectId);

            var time     = DateTime.UtcNow.AddDays(-1);
            var incident = DB.Incidents.FirstOrDefault(x => x.ProjectId == projectId && x.Title == title && x.Severity == severity && x.CreatedTime >= time);

            if (incident != null)
            {
                incident.CreatedTime   = DateTime.UtcNow;
                incident.MitigatedTime = null;
                incident.ResolvedTime  = null;
                incident.UserId        = null;
                incident.HitCount++;
                incident.Status   = IncidentStatus.Active;
                incident.Summary += "\r\n\r\n" + DateTime.UtcNow.ToString() + "(UTC):\r\n\r\n" + body;

                DB.CallHistories
                .Where(x => x.IncidentId == incident.Id)
                .SetField(x => x.Ignore).WithValue(true)
                .Update();
            }
            else
            {
                incident = new Models.Incident
                {
                    CreatedTime = DateTime.UtcNow,
                    ProjectId   = projectId,
                    Title       = title,
                    Summary     = DateTime.UtcNow.ToString() + "(UTC):\r\n\r\n" + body,
                    Severity    = severity
                };
                DB.Incidents.Add(incident);
            }

            await DB.SaveChangesAsync();

            return(Json(new { code = 200, data = incident.Id }));
        }
 public bool Put(Models.Incident incident)
 {
     incident.Updated = DateTime.Now;
     _repository.Update(incident);
     return(true);
 }
        public bool ListIncidents(string itype, string istatus, ref string errorMessage, ref List <IO.Swagger.Models.Incident> results)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    //Make query
                    if (itype != null && istatus != null)
                    {
                        var incidents = (from d in context.Incident
                                         where d.Status == istatus && d.Type == itype
                                         select new
                                         { id = d.Incidentid, description = d.Description, itime = d.Incidenttime, iplan = d.Interventionplan, position = d.Position, prio = d.Prio, probability = d.Probability, status = d.Status, itype = d.Type, wid = d.WearablePhysicalId, phone = d.PhoneNumber, additionalMedia = d.AdditionalMedia, mediaType = d.AdditionalMediaType }
                                         ).ToList();

                        if (incidents == null)
                        {
                            errorMessage = "No incidents";
                            retVal       = false;
                        }
                        else
                        {
                            foreach (var loc in incidents)
                            {
                                IO.Swagger.Models.Incident z = new Models.Incident();
                                z.Description      = loc.description;
                                z.Incidentid       = loc.id;
                                z.Incidenttime     = loc.itime;
                                z.Interventionplan = loc.iplan;
                                z.Position         = loc.position;
                                z.Prio             = loc.prio;
                                z.Probability      = (decimal)loc.probability;
                                z.Status           = loc.status;
                                z.Type             = loc.itype;
                                z.Wbid             = loc.wid;
                                z.Telephone        = loc.phone;
                                z.AdditionalMedia  = loc.additionalMedia;
                                z.MediaType        = loc.mediaType;
                                results.Add(z);
                            }
                        }
                    }

                    //Make query
                    else if (istatus != null)
                    {
                        var incidents = (from d in context.Incident
                                         where d.Status == istatus
                                         select new
                                         { id = d.Incidentid, description = d.Description, itime = d.Incidenttime, iplan = d.Interventionplan, position = d.Position, prio = d.Prio, probability = d.Probability, status = d.Status, itype = d.Type, wid = d.WearablePhysicalId, phone = d.PhoneNumber, additionalMedia = d.AdditionalMedia, mediaType = d.AdditionalMediaType }
                                         ).ToList();

                        if (incidents == null)
                        {
                            errorMessage = "No incidents";
                            retVal       = false;
                        }
                        else
                        {
                            foreach (var loc in incidents)
                            {
                                IO.Swagger.Models.Incident z = new Models.Incident();
                                z.Description      = loc.description;
                                z.Incidentid       = loc.id;
                                z.Incidenttime     = loc.itime;
                                z.Interventionplan = loc.iplan;
                                z.Position         = loc.position;
                                z.Prio             = loc.prio;
                                z.Probability      = (decimal)loc.probability;
                                z.Status           = loc.status;
                                z.Type             = loc.itype;
                                z.Wbid             = loc.wid;
                                z.Telephone        = loc.phone;
                                z.AdditionalMedia  = loc.additionalMedia;
                                z.MediaType        = loc.mediaType;
                                results.Add(z);
                            }
                        }
                    }

                    else if (itype != null)
                    {
                        var incidents = (from d in context.Incident
                                         where d.Type == itype
                                         select new
                                         { id = d.Incidentid, description = d.Description, itime = d.Incidenttime, iplan = d.Interventionplan, position = d.Position, prio = d.Prio, probability = d.Probability, status = d.Status, itype = d.Type, wid = d.WearablePhysicalId, phone = d.PhoneNumber, additionalMedia = d.AdditionalMedia, mediaType = d.AdditionalMediaType }
                                         ).ToList();

                        if (incidents == null)
                        {
                            errorMessage = "No incidents";
                            retVal       = false;
                        }
                        else
                        {
                            foreach (var loc in incidents)
                            {
                                IO.Swagger.Models.Incident z = new Models.Incident();
                                z.Description      = loc.description;
                                z.Incidentid       = loc.id;
                                z.Incidenttime     = loc.itime;
                                z.Interventionplan = loc.iplan;
                                z.Position         = loc.position;
                                z.Prio             = loc.prio;
                                z.Probability      = (decimal)loc.probability;
                                z.Status           = loc.status;
                                z.Type             = loc.itype;
                                z.Wbid             = loc.wid;
                                z.Telephone        = loc.phone;
                                z.AdditionalMedia  = loc.additionalMedia;
                                z.MediaType        = loc.mediaType;
                                results.Add(z);
                            }
                        }
                    }
                    else
                    {
                        var incidents = (from d in context.Incident
                                         select new
                                         { id = d.Incidentid, description = d.Description, itime = d.Incidenttime, iplan = d.Interventionplan, position = d.Position, prio = d.Prio, probability = d.Probability, status = d.Status, itype = d.Type, wid = d.WearablePhysicalId, phone = d.PhoneNumber, additionalMedia = d.AdditionalMedia, mediaType = d.AdditionalMediaType }
                                         ).ToList();

                        if (incidents == null)
                        {
                            errorMessage = "No incidents";
                            retVal       = false;
                        }
                        else
                        {
                            foreach (var loc in incidents)
                            {
                                IO.Swagger.Models.Incident z = new Models.Incident();
                                z.Description      = loc.description;
                                z.Incidentid       = loc.id;
                                z.Incidenttime     = loc.itime;
                                z.Interventionplan = loc.iplan;
                                z.Position         = loc.position;
                                z.Prio             = loc.prio;
                                z.Probability      = (decimal)loc.probability;
                                z.Status           = loc.status;
                                z.Type             = loc.itype;
                                z.Wbid             = loc.wid;
                                z.Telephone        = loc.phone;
                                z.AdditionalMedia  = loc.additionalMedia;
                                z.MediaType        = loc.mediaType;
                                results.Add(z);
                            }
                        }
                    }
                    //Insert role connection;
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
Beispiel #9
0
 public Models.Incident Add(Models.Incident incident)
 {
     _incidentModel.Incidents.Add(incident);
     return(incident);
 }