Пример #1
0
        public ActionResult SendAlertMessage(String alertMessage, string selectedTrucks)
        {
            List <FleetVehicle> fleetVehicles = new List <FleetVehicle>();
            List <User>         users         = new List <User>();

            using (FSPDataContext dc = new FSPDataContext())
            {
                fleetVehicles = dc.FleetVehicles.ToList();
                users         = dc.Users.ToList();
            }

            using (TowTruckServiceRef.TowTruckServiceClient service = new TowTruckServiceRef.TowTruckServiceClient())
            {
                var trucks = new JavaScriptSerializer().Deserialize <IEnumerable <SelectedTruck> >(selectedTrucks);
                foreach (var truck in trucks)
                {
                    TowTruckServiceRef.TruckMessage message = new TowTruckServiceRef.TruckMessage();
                    message.MessageID   = Guid.NewGuid();
                    message.MessageText = alertMessage;
                    message.TruckIP     = fleetVehicles.Where(p => p.VehicleNumber == truck.truckNumber).FirstOrDefault().IPAddress;
                    message.UserID      = users.Where(p => p.Email == User.Identity.Name).FirstOrDefault().UserID;
                    message.SentTime    = DateTime.Now;
                    service.SendMessage(message);
                }
            }

            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public ActionResult SendDriverMessage(string message, int requireAck, List <MtcTruck> trucks)
        {
            using (var service = new TowTruckServiceClient())
            {
                foreach (var truck in trucks)
                {
                    var svcMessage = new TowTruckServiceRef.TruckMessage
                    {
                        MessageID   = Guid.NewGuid(),
                        MessageText = message,
                        TruckIP     = truck.ipAddress,
                        UserEmail   = HttpContext.User.Identity.Name,
                        SentTime    = DateTime.Now,
                        MessageType = requireAck
                    };

                    service.SendMessage(svcMessage);
                }
            }

            return(Json(true, JsonRequestBehavior.AllowGet));
        }