Exemplo n.º 1
0
 public string UpdateIncident(IncidentRequest incident)
 {
     jsonclass.incidentResponses.FirstOrDefault(a => a.IncidentId == incident.IncidentId).incStatus = incident.incStatus;
     Console.WriteLine("1." + incident.incStatus);
     Console.WriteLine("2." + incident.IncidentId);
     return("");
 }
Exemplo n.º 2
0
        /// <summary>
        /// Validates Incident before creates
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static void ValidateIncidentCreate(IncidentRequest request)
        {
            var result = dbContext.Incidents.Any(i => (i.Status == 0 || i.Status == null) && i.Deleted == false);

            if (result)
            {
                var response = HttpUtilities.FrameHTTPResp(System.Net.HttpStatusCode.BadRequest, ErrorCodes.INPROGRESS_INCIDENT_EXISTS);
                throw new HttpResponseException(response);
            }
            //check for duplicate MPRNs:
            CheckDuplicateMPRNS(request.MPRNs);
        }
        public IncidentRequestViewModel()
        {
            IncidentRequest.Add(new SelectListItem {
                Text = "Incident", Value = "0"
            });
            IncidentRequest.Add(new SelectListItem {
                Text = "Request", Value = "1"
            });

            priorityList.Add(new SelectListItem {
                Text = "Low", Value = "0"
            });
            priorityList.Add(new SelectListItem {
                Text = "Medium", Value = "1"
            });
            priorityList.Add(new SelectListItem {
                Text = "High", Value = "2"
            });
        }
Exemplo n.º 4
0
        public async Task <IActionResult> AddIncident([FromBody] IncidentRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            UserEntity userEntity = await _userHelper.GetUserAsync(request.UserId);

            if (userEntity == null)
            {
                return(BadRequest("User doesn't exists."));
            }

            TaxiEntity taxiEntity = await _context.Taxis.FirstOrDefaultAsync(t => t.Plate == request.Plate);

            if (taxiEntity == null)
            {
                _context.Taxis.Add(new TaxiEntity {
                    Plate = request.Plate.ToUpper()
                });
                await _context.SaveChangesAsync();

                taxiEntity = await _context.Taxis.FirstOrDefaultAsync(t => t.Plate == request.Plate);
            }

            TripEntity tripEntity = new TripEntity
            {
                Source          = request.Address,
                SourceLatitude  = request.Latitude,
                SourceLongitude = request.Longitude,
                StartDate       = DateTime.UtcNow,
                Taxi            = taxiEntity,
                EndDate         = DateTime.UtcNow,
                Qualification   = 1,
                Remarks         = request.Remarks,
                Target          = request.Address,
                TargetLatitude  = request.Latitude,
                TargetLongitude = request.Longitude,
                TripDetails     = new List <TripDetailEntity>
                {
                    new TripDetailEntity
                    {
                        Date      = DateTime.UtcNow,
                        Latitude  = request.Latitude,
                        Longitude = request.Longitude
                    },
                    new TripDetailEntity
                    {
                        Date      = DateTime.UtcNow,
                        Latitude  = request.Latitude,
                        Longitude = request.Longitude
                    }
                },
                User = userEntity,
            };

            _context.Trips.Add(tripEntity);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Exemplo n.º 5
0
        public async Task <ActionResult> addnewIncident(IncidentRequest incidentRequest)
        {
            string   incidentId = Guid.NewGuid().ToString();
            Incident incident   = new Incident
            {
                Id               = incidentId,
                UserAccountId    = incidentRequest.UserAccountId,
                IncidentTypeId   = incidentRequest.IncidentTypeId,
                IncidentPic      = incidentRequest.IncidentPic,
                Address          = incidentRequest.Address,
                AddressLine      = incidentRequest.AddressLine,
                CoordinateX      = incidentRequest.CoordinateX,
                CoordinateY      = incidentRequest.CoordinateY,
                CustomerComments = incidentRequest.CustomerComments,
                Status           = incidentRequest.Status,
                Deleted          = false,
                CreatedAt        = DateTime.Now
            };

            appDbContex.Incidents.Add(incident);
            await appDbContex.SaveChangesAsync();

            List <ApplicationUser> usersToNotify = new List <ApplicationUser>();
            FindUsers findUsers = new FindUsers(appDbContex, userManager);

            usersToNotify = findUsers.FindUsersToNotifybyCoordinateXY(incidentRequest.CoordinateX, incidentRequest.CoordinateY, incidentRequest.IncidentTypeId);

            PushNotificationLogic pushNotificationLogic = new PushNotificationLogic();
            //  string[] androidDeviceTocken;
            List <string> androidDeviceTocken = new List <string>();

            SendSms sendsms             = new SendSms();
            var     incidenttypeName    = appDbContex.IncidentTypes.Where(a => a.Id == incidentRequest.IncidentTypeId).FirstOrDefault();
            string  contactNumber       = string.Empty;
            string  location            = "http://maps.google.com/?q=" + incidentRequest.CoordinateX + "," + incidentRequest.CoordinateY + "";
            string  notificationMessage = string.Empty;

            foreach (var user in usersToNotify)
            {
                //if (user.Source == "Android")
                //{
                //    androidDeviceTocken.Add(user.PushTokenId);
                //}


                if (user.EmergencyContactNo != null)
                {
                    //Notification to Emergency Contact
                    contactNumber       = user.InternationalPrefix.ToString() + user.PhoneNumber.ToString();
                    notificationMessage = "Here is the " + incidenttypeName.Name + " incident happen... please click here " + location;
                    //   sendsms.SendTextSms(notificationMessage, contactNumber);
                }
                else
                {
                    //Notification to Application Users
                    contactNumber       = user.InternationalPrefix.ToString() + user.PhoneNumber.ToString();
                    notificationMessage = "Here is the " + incidenttypeName.Name + " incident happen... please click here " + location;
                    //  sendsms.SendTextSms(notificationMessage, contactNumber);
                }

                NotifiedUser notifiedUser = new NotifiedUser
                {
                    Id         = Guid.NewGuid().ToString(),
                    IncidentId = incidentId,
                    UserId     = user.Id,
                    CreatedAt  = DateTime.Now
                };
                appDbContex.NotifiedUsers.Add(notifiedUser);
                await appDbContex.SaveChangesAsync();

                IncidentUserMessage incidentUserMessage = new IncidentUserMessage
                {
                    Id            = Guid.NewGuid().ToString(),
                    IncidentId    = incidentId,
                    UserId        = user.Id,
                    Status        = incidentRequest.Status,
                    StatusMessage = notificationMessage,
                    CreatedAt     = DateTime.Now
                };

                appDbContex.IncidentUserMessages.Add(incidentUserMessage);
                await appDbContex.SaveChangesAsync();
            }

            try
            {
                //  androidDeviceTocken = null;
                //  androidDeviceTocken.Add("f4e9GJxSvYA:APA91bGkImijMYelYhFCqFTE6qDzEfzeEdM6H3Q1XwxxCDvYWZGdyviRGtPSdTcyeXy4787JPwfb04pFNWo5dXIc420EVZEQ15UtHqTCAn8kk8zdAJ8pgRLLMNbKkJ1dfR5ABMoMJd71");
                //  androidDeviceTocken.Add("ccSVgC04gaM:APA91bGt8rDg-1CyG5N9pxW5aXWs9x4jpf6rXYXRu0usnaiMzgfosr5Guv89iJbiHBvUcOYkGf2RIJBx_-jtK_76bZwk__d3Xn94TSXLmaC8rs9GEnIvX5AOldPXqp1EiUvIrt1zfQcr");

                androidDeviceTocken.Add("dndndqNSHbs:APA91bFrO7Au5DvoYIgFaWY1S7PLAzzcwZ9EcuwjKvqFBdM-733zwDKCWnT5JZ9FcSVsUb1JwYUWCElXmFpgd6BXkTcUn9ejhvrwvB0eIC9Mpn4komqfT_APS2TaX9ZtZ_a_TbjfFswH");
                if (androidDeviceTocken != null)
                {
                    //     Myobject myobj = new Myobject
                    //    {
                    //        Name = "Bhavin",
                    //        City = "vapi"
                    //    };

                    var myobj = new { Name = "Bhavin", City = "Vapi" };


                    await pushNotificationLogic.SendPushNotification(androidDeviceTocken, "SecureAfrica", notificationMessage, myobj);
                }
            }
            catch (Exception ex)
            {
            }
            await _hubContext.Clients.All.BroadcastMessage("success", "this is our msg");

            return(Ok(new { Message = "Incident added successfully !" }));
        }
Exemplo n.º 6
0
        public async Task <Response> AddIncident(string urlBase, string servicePrefix, string controller, IncidentRequest model, string tokenType, string accessToken)
        {
            try
            {
                string        request = JsonConvert.SerializeObject(model);
                StringContent content = new StringContent(request, Encoding.UTF8, "application/json");
                HttpClient    client  = new HttpClient
                {
                    BaseAddress = new Uri(urlBase)
                };

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(tokenType, accessToken);
                string url = $"{servicePrefix}{controller}";
                HttpResponseMessage response = await client.PostAsync(url, content);

                string answer = await response.Content.ReadAsStringAsync();

                if (!response.IsSuccessStatusCode)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = answer,
                    });
                }

                return(new Response {
                    IsSuccess = true
                });
            }
            catch (Exception ex)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = ex.Message,
                });
            }
        }
Exemplo n.º 7
0
        public bool PostIncidents([FromBody] IncidentRequest incident)
        {
            #region VALIDATION
            HttpResponseMessage errorResponseMessage = null;

            #region CHECK VALUES
            if (incident == null)
            {
                errorResponseMessage = new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new StringContent("Invalid request. No model received.")
                }
            }
            ;

            else if (incident.kind == null)
            {
                errorResponseMessage = new HttpResponseMessage(HttpStatusCode.Conflict)
                {
                    Content = new StringContent("The incident type cannot be null")
                }
            }
            ;

            // Get a collection with the allowed values
            else if (!Enum.GetNames(typeof(Incident.AllowedIncidents)).Contains(incident.kind = incident.kind.ToUpper().Trim()))
            {
                errorResponseMessage = new HttpResponseMessage(HttpStatusCode.Conflict)
                {
                    Content = new StringContent($"Invalid incident type: \"{incident.kind}\"")
                }
            }
            ;

            else if (incident.happenedAt == null)
            {
                errorResponseMessage = new HttpResponseMessage(HttpStatusCode.Conflict)
                {
                    Content = new StringContent("Invalid date")
                }
            }
            ;

            else if (registeredLocalities.Count(obj => obj._id == incident.locationId) == 0)
            {
                errorResponseMessage = new HttpResponseMessage(HttpStatusCode.Conflict)
                {
                    Content = new StringContent($"Invalid location ID: \"{incident.locationId}\"")
                }
            }
            ;
            #endregion

            if (errorResponseMessage != null)
            {
                // Throw an error instead of returning "false" to give information to the requester
                throw new HttpResponseException(errorResponseMessage);
            }
            #endregion

            registeredIncidents.Add(new Incident
            {
                _id        = Guid.NewGuid().ToString().Replace("-", ""),
                kind       = incident.kind,
                happenedAt = (DateTime)incident.happenedAt,
                isArchived = false,
                locationId = incident.locationId
            });

            return(true);
        }
        public async Task <HttpResponseMessage> CustomerNewIncident(IncidentRequest incidentRequest)
        {
            Services.Log.Info("New Incident Request [API]");

            // Get the logged-in user.
            var currentUser = this.User as ServiceUser;

            double locationX = 0;
            double locationY = 0;

            //Check Provided Location JObject & Process Accordingly
            if (incidentRequest.Location != null)
            {
                if (incidentRequest.Location.X != -1 && incidentRequest.Location.Y != -1)
                {
                    //Coordinates Flow - X & Y Coordinate Passed
                    locationX = incidentRequest.Location.X;
                    locationY = incidentRequest.Location.Y;
                }
                else
                {
                    //No Coordinates
                    //Consider Geocoding
                }
            }
            else
            {
                //No Location Flow - No Location JObject
            }

            Incident newIncident = new Incident()
            {
                Id                    = Guid.NewGuid().ToString(),
                JobCode               = incidentRequest.JobCode,
                LocationObj           = await JsonConvert.SerializeObjectAsync(incidentRequest.Location),
                CoordinateX           = locationX,
                CoordinateY           = locationY,
                ProviderUserID        = currentUser.Id,
                VehicleGUID           = incidentRequest.VehicleGUID,
                AdditionalDetails     = incidentRequest.AdditionalDetails,
                StatusCode            = "SUBMITTED", // Set the Initial Status
                StatusCustomerConfirm = true,
                StatusProviderConfirm = false,
                ServiceFee            = (incidentRequest.ServiceFee != 0 || incidentRequest.ServiceFee != null) ? incidentRequest.ServiceFee : 0
            };

            stranddContext context = new stranddContext();

            context.Incidents.Add(newIncident);

            await context.SaveChangesAsync();

            Services.Log.Info("New Incident Created [" + newIncident.Id + "]");

            IncidentRequestResponse returnObject = new IncidentRequestResponse {
                IncidentGUID = newIncident.Id
            };
            string responseText = JsonConvert.SerializeObject(returnObject);

            //Notifying Connect WebClients with IncidentInfo Package
            IHubContext hubContext = Services.GetRealtime <IncidentHub>();

            hubContext.Clients.All.saveNewIncidentCustomer(new IncidentInfo(newIncident));
            ProcessProviderOutreach(newIncident, Services);

            Services.Log.Info("Connected Clients Updated");

            SendGridController.SendIncidentSubmissionAdminEmail(newIncident, Services);

            await HistoryEvent.logHistoryEventAsync("INCIDENT_NEW_CUSTOMER", null, newIncident.Id, null, currentUser.Id, null);

            return(this.Request.CreateResponse(HttpStatusCode.Created, responseText));
        }
        public string UpdateIncident(IncidentRequest incident)
        {
            var res = new IncidentService().UpdateIncident(incident);

            return("true");
        }