Esempio n. 1
0
        public ActionResult Create(CommViewModel cvm)
        {
            try {
                // TODO: Add insert logic here
                if (cvm.Message.Trim().Length > 0)
                {
                    MSTR_Comms Comms = new MSTR_Comms();
                    Comms.Message   = cvm.Message;
                    Comms.CreatedBy = exLogic.Util.getLoginUserID();
                    ctx.MSTR_Comms.Add(Comms);
                    ctx.SaveChanges();

                    List <MSTR_User> UserList = ctx.MSTR_User.Where(x => x.AccountId == 1).ToList();

                    foreach (MSTR_User Us in UserList)
                    {
                        CommsDetail Cmd = new CommsDetail();
                        Cmd.FromID    = exLogic.Util.getLoginUserID();
                        Cmd.ToID      = Us.UserId;
                        Cmd.MessageID = Comms.MessageID;
                        Cmd.Status    = "NEW";
                        Cmd.CreatedBy = exLogic.Util.getLoginUserID();
                        ctx.CommsDetail.Add(Cmd);
                    }
                    ctx.SaveChanges();
                }
                return(RedirectToAction("Index"));
            } catch (Exception Ex) {
                return(View());
            }
        }
Esempio n. 2
0
        public JsonResult SaveZone(MSTR_NoFlyZone Zone)
        {
            MSTR_NoFlyZone ezone = new MSTR_NoFlyZone();

            if (Zone.ID != 0)
            {
                ezone                 = ctx.MSTR_NoFlyZone.Where(x => x.ID == Zone.ID).FirstOrDefault();
                ezone.Name            = Zone.Name;
                ezone.Coordinates     = Zone.Coordinates;
                ezone.FillColour      = "Orange";
                ezone.StartDate       = Zone.StartDate;
                ezone.EndDate         = Zone.EndDate;
                ezone.StartTime       = Zone.StartTime;
                ezone.EndTime         = Zone.EndTime;
                ezone.ZoneDescription = Zone.ZoneDescription;
                ezone.DisplayType     = "Dynamic";
                ezone.Message         = Zone.Message;
                ezone.IsDeleted       = false;
                ctx.SaveChanges();
            }
            else
            {
                ezone             = Zone;
                ezone.FillColour  = "Orange";
                ezone.DisplayType = "Dynamic";
                ezone.IsDeleted   = false;

                ctx.MSTR_NoFlyZone.Add(ezone);
                ctx.SaveChanges();
            }
            var flUSer = GetActivePilots();
            int UserID = exLogic.Util.getLoginUserID();

            foreach (PilotFlight pil in flUSer)
            {
                int Pilotid = pil.PilotID.GetValueOrDefault();
                if (Pilotid != 0)
                {
                    MSTR_Comms mcom = new MSTR_Comms();
                    mcom.CreatedBy = UserID;
                    mcom.Message   = Zone.Message;
                    mcom.FlightID  = pil.FlightID;
                    ctx.MSTR_Comms.Add(mcom);
                    ctx.SaveChanges();

                    CommsDetail cdet = new CommsDetail();
                    cdet.FromID          = UserID;
                    cdet.ToID            = pil.PilotID.Value;
                    cdet.MessageID       = mcom.MessageID;
                    cdet.Status          = "NEW";
                    cdet.StatusUpdatedOn = DateTime.Now;
                    cdet.CreatedBy       = UserID;
                    ctx.CommsDetail.Add(cdet);
                    ctx.SaveChanges();
                }
            }
            List <MSTR_NoFlyZone> NoFlyZoneList = ctx.MSTR_NoFlyZone.ToList();

            return(Json(ezone.ID, JsonRequestBehavior.AllowGet));
        }
Esempio n. 3
0
        public JsonResult CreateMessage(string Message, int FlightID)
        {
            try {
                // TODO: Add insert logic here
                int userid = exLogic.Util.getLoginUserID();
                if (userid != 0)
                {
                    if (Message.Trim().Length > 0)
                    {
                        MSTR_Comms Comms = new MSTR_Comms();
                        Comms.Message   = Message;
                        Comms.CreatedBy = userid;
                        Comms.FlightID  = FlightID;

                        ctx.MSTR_Comms.Add(Comms);
                        ctx.SaveChanges();

                        List <MSTR_User> UserList = ctx.MSTR_User.Where(x => x.AccountId == 1).ToList();

                        foreach (MSTR_User Us in UserList)
                        {
                            CommsDetail Cmd = new CommsDetail();
                            Cmd.FromID    = exLogic.Util.getLoginUserID();
                            Cmd.ToID      = Us.UserId;
                            Cmd.MessageID = Comms.MessageID;
                            Cmd.Status    = "NEW";
                            Cmd.CreatedBy = exLogic.Util.getLoginUserID();
                            ctx.CommsDetail.Add(Cmd);
                        }
                        ctx.SaveChanges();
                        return(Json("OK"));
                    }
                    else
                    {
                        return(Json("Empty Message"));
                    }
                }
                else
                {
                    return(Json("Invalid User"));
                }
            } catch (Exception Ex) {
                return(Json("Unsuccessful"));
            }
        }
Esempio n. 4
0
        public JsonResult CreateMessageToUser(string Message, int FlightID)
        {
            try
            {
                // TODO: Add insert logic here
                int?ToID = ctx.DroneFlight.Where(x => x.ID == FlightID).Select(x => x.PilotID).FirstOrDefault();

                int userid = exLogic.Util.getLoginUserID();
                if (userid != 0)
                {
                    if (Message.Trim().Length > 0)
                    {
                        MSTR_Comms Comms = new MSTR_Comms();
                        Comms.Message   = Message;
                        Comms.CreatedBy = userid;
                        Comms.FlightID  = FlightID;

                        ctx.MSTR_Comms.Add(Comms);
                        ctx.SaveChanges();
                        CommsDetail Cmd = new CommsDetail();
                        Cmd.FromID    = userid;
                        Cmd.ToID      = ToID.Value;
                        Cmd.MessageID = Comms.MessageID;
                        Cmd.Status    = "NEW";
                        Cmd.CreatedBy = exLogic.Util.getLoginUserID();
                        ctx.CommsDetail.Add(Cmd);
                        ctx.SaveChanges();
                        return(Json("OK"));
                    }
                    else
                    {
                        return(Json("Empty Message"));
                    }
                }
                else
                {
                    return(Json("Invalid User"));
                }
            }
            catch (Exception Ex)
            {
                return(Json("Unsuccessful"));
            }
        }
Esempio n. 5
0
        public JsonResult SendMessage(CommsSender Comm)
        {
            if (Comm.OrganizationID > 0)
            {
                if (Comm.PilotID > 0)
                {
                    MSTR_Comms mcom = new MSTR_Comms();
                    mcom.CreatedBy = 1;
                    mcom.Message   = Comm.Message;
                    ctx.MSTR_Comms.Add(mcom);
                    ctx.SaveChanges();

                    CommsDetail cdet = new CommsDetail();
                    cdet.FromID          = exLogic.Util.getLoginUserID();
                    cdet.ToID            = Comm.PilotID;
                    cdet.MessageID       = mcom.MessageID;
                    cdet.Status          = "NEW";
                    cdet.StatusUpdatedOn = DateTime.Now;
                    cdet.CreatedBy       = exLogic.Util.getLoginUserID();
                    ctx.CommsDetail.Add(cdet);
                    ctx.SaveChanges();
                }
            }
            else if (Comm.OrganizationID == 0)
            {
                if (Comm.ActivePilot == true)
                {
                    var flUSer = GetActivePilots();
                    foreach (PilotFlight pil in flUSer)
                    {
                        int Pilotid = pil.PilotID.GetValueOrDefault();
                        if (Pilotid != 0)
                        {
                            MSTR_Comms mcom = new MSTR_Comms();
                            mcom.CreatedBy = exLogic.Util.getLoginUserID();
                            mcom.Message   = Comm.Message;
                            mcom.FlightID  = pil.FlightID;
                            ctx.MSTR_Comms.Add(mcom);
                            ctx.SaveChanges();

                            CommsDetail cdet = new CommsDetail();
                            cdet.FromID          = exLogic.Util.getLoginUserID();
                            cdet.ToID            = pil.PilotID.Value;
                            cdet.MessageID       = mcom.MessageID;
                            cdet.Status          = "NEW";
                            cdet.StatusUpdatedOn = DateTime.Now;
                            cdet.CreatedBy       = exLogic.Util.getLoginUserID();
                            ctx.CommsDetail.Add(cdet);
                            ctx.SaveChanges();
                        }
                    }
                }
                else if (Comm.ActiveRegionPilot == true)
                {
                    List <PilotFlight> actPilotRegion = GetActivePilotsRegion(Comm.Zone);
                    foreach (PilotFlight pil in actPilotRegion)
                    {
                        int Pilotid = pil.PilotID.GetValueOrDefault();
                        if (Pilotid != 0)
                        {
                            MSTR_Comms mcom = new MSTR_Comms();
                            mcom.CreatedBy = exLogic.Util.getLoginUserID();
                            mcom.Message   = Comm.Message;
                            mcom.FlightID  = pil.FlightID;
                            ctx.MSTR_Comms.Add(mcom);
                            ctx.SaveChanges();

                            CommsDetail cdet = new CommsDetail();
                            cdet.FromID          = exLogic.Util.getLoginUserID();
                            cdet.ToID            = pil.PilotID.Value;
                            cdet.MessageID       = mcom.MessageID;
                            cdet.Status          = "NEW";
                            cdet.StatusUpdatedOn = DateTime.Now;
                            cdet.CreatedBy       = exLogic.Util.getLoginUserID();
                            ctx.CommsDetail.Add(cdet);
                            ctx.SaveChanges();
                        }
                    }
                }
                else
                {
                    List <int> mPils = ctx.MSTR_User.Where(x => x.AccountId != 1 && x.IsPilot == true).Select(x => x.UserId).ToList();
                    foreach (int pil in mPils)
                    {
                        MSTR_Comms mcom = new MSTR_Comms();
                        mcom.CreatedBy = exLogic.Util.getLoginUserID();
                        mcom.Message   = Comm.Message;
                        ctx.MSTR_Comms.Add(mcom);
                        ctx.SaveChanges();

                        CommsDetail cdet = new CommsDetail();
                        cdet.FromID          = exLogic.Util.getLoginUserID();
                        cdet.ToID            = pil;
                        cdet.MessageID       = mcom.MessageID;
                        cdet.Status          = "NEW";
                        cdet.StatusUpdatedOn = DateTime.Now;
                        cdet.CreatedBy       = exLogic.Util.getLoginUserID();
                        ctx.CommsDetail.Add(cdet);
                        ctx.SaveChanges();
                    }
                }
            }

            return(Json("OK"));
        }