public ActionResult PostDeletehandheld([FromBody] JObject rqhdr)
        {
            var selectedHandheldid = Convert.ToInt32(Newtonsoft.Json.JsonConvert.DeserializeObject <string>(rqhdr["handheldid"].ToString(), new Newtonsoft.Json.JsonSerializerSettings {
                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            }));
            var serial = Convert.ToInt32(Newtonsoft.Json.JsonConvert.DeserializeObject <string>(rqhdr["serial"].ToString(), new Newtonsoft.Json.JsonSerializerSettings {
                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            }));

            Users user = new Users();

            user.Userid = Convert.ToInt32(rqhdr["userid"]);

            var result = _context.Handhelds.FirstOrDefault <Handhelds>(e => e.Handheldid == selectedHandheldid);

            if (result == null)
            {
                Operationlogs ol_failed = new Operationlogs();
                ol_failed.Userid      = user.Userid;
                ol_failed.Operationid = Handler_Operations.Opeartion_DeleteHandHeld;
                ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                ol_failed.Text        = "لم يتم العثور على لاسلكي بالرقم: " + serial.ToString();
                _oper.Add_New_Operation_Log(ol_failed);
                return(Ok(ol_failed.Text));
            }

            var ahwal_mapping_exists = _context.Ahwalmapping.FirstOrDefault <Ahwalmapping>(e => e.Handheldid == selectedHandheldid && e.Hasdevices == 1);

            if (ahwal_mapping_exists != null)
            {
                Operationlogs ol_failed = new Operationlogs();
                ol_failed.Userid      = user.Userid;
                ol_failed.Operationid = Handler_Operations.Opeartion_DeleteHandHeld;
                ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                ol_failed.Text        = "جهاز لاسلكي قيد الاستخدام: " + serial;
                _oper.Add_New_Operation_Log(ol_failed);
                return(Ok(ol_failed.Text));
            }


            _context.Handhelds.Remove(result);

            _context.SaveChanges();

            Operationlogs ol = new Operationlogs();

            ol.Userid      = user.Userid;
            ol.Operationid = Handler_Operations.Opeartion_UpdateHandHeld;
            ol.Statusid    = Handler_Operations.Opeartion_Status_Success;
            ol.Text        = "تم حذف لاسلكي بالرقم: " + result.Handheldid;
            _oper.Add_New_Operation_Log(ol);
            return(Ok(ol.Text));

            //string Qry = "delete from handhelds  where handheldid=" + frm.Handheldid;

            //return Ok(DAL.PostGre_ExNonQry(Qry));
        }
예제 #2
0
        public Operationlogs updatePersonState([FromQuery] string selmenu, [FromQuery] int ahwalMappingID, [FromQuery] int Userid)
        {
            //string ol_label = "";
            int PatrolPersonStateID = 0;

            if (selmenu == "غياب")
            {
                PatrolPersonStateID = Core.Handler_AhwalMapping.PatrolPersonState_Absent;
            }
            else if (selmenu == "مرضيه")
            {
                PatrolPersonStateID = Core.Handler_AhwalMapping.PatrolPersonState_Sick;
            }
            else if (selmenu == "اجازه")
            {
                PatrolPersonStateID = Core.Handler_AhwalMapping.PatrolPersonState_Off;
            }

            Ahwalmapping person_mapping_exists = GetAhwal(ahwalMappingID);

            if (person_mapping_exists == null)
            {
                Operationlogs ol_failed = new Operationlogs();
                ol_failed.Userid      = Userid;
                ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_Ahwal_ChangePersonState;
                ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                ol_failed.Text        = "لم يتم العثور على التوزيع";
                Handler_Operations.Add_New_Operation_Log(ol_failed);
                return(ol_failed);
            }


            Persons GetPerson = GetPersonById(person_mapping_exists.Personid);

            if (GetPerson == null)
            {
                Operationlogs ol_failed = new Operationlogs();
                ol_failed.Userid      = Userid;
                ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_Ahwal_ChangePersonState;
                ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                ol_failed.Text        = "لم يتم العثور على الفرد: " + person_mapping_exists.Personid; //todo, change it actual person name
                Handler_Operations.Add_New_Operation_Log(ol_failed);
                return(ol_failed);
            }

            //last check
            //if he has devices, dont change his state to anything
            if (Convert.ToBoolean(person_mapping_exists.Hasdevices))
            {
                Operationlogs ol_failed = new Operationlogs();
                ol_failed.Userid      = Userid;
                ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_Ahwal_ChangePersonState;
                ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                ol_failed.Text        = "هذا المستخدم يملك حاليا اجهزة";
                Handler_Operations.Add_New_Operation_Log(ol_failed);
                return(ol_failed);
            }

            Operationlogs ol  = new Operationlogs();
            int           ret = 0;
            string        Qry = "";

            Qry = "update AhwalMapping set PatrolPersonStateID = " + PatrolPersonStateID + " , LastStateChangeTimeStamp = '" + DateTime.Now + "' where AhwalMappingId = " + ahwalMappingID;
            ret = DAL.PostGre_ExNonQry(Qry);
            Qry = "insert into patrolpersonstatelog (Userid,PatrolPersonStateID,TimeStamp,Personid) values(" + Userid + " , " + PatrolPersonStateID + " , '" + DateTime.Now + "' , " + person_mapping_exists.Personid + ")";
            ret = DAL.PostGre_ExNonQry(Qry);
            if (ret > 0)
            {
                ol.Userid      = Userid;
                ol.Operationid = Handler_Operations.Opeartion_Mapping_Ahwal_ChangePersonState;
                ol.Statusid    = Handler_Operations.Opeartion_Status_Success;
                ol.Text        = "احوال تغيير حالة الفرد " + GetPerson.Milnumber + " " + GetPerson.Name;
                return(ol);
            }
            ol.Statusid = Handler_Operations.Opeartion_Status_Failed;
            ol.Text     = "Failed";
            return(ol);
        }
예제 #3
0
        public Operationlogs PostAddAhwalMapping([FromBody] JObject data)
        {
            Ahwalmapping frm = Newtonsoft.Json.JsonConvert.DeserializeObject <Ahwalmapping>(data["ahwalmappingobj"].ToString(), new Newtonsoft.Json.JsonSerializerSettings {
                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            });
            Users u = data["userobj"].ToObject <Users>();
            //  GetPerson = "";
            // string ol_failed = "";
            //Operationlogs ol = new Operationlogs();
            //we have to check first that this person doesn't exists before in mapping
            Persons GetPerson = GetPersonById(frm.Personid);

            if (GetPerson == null)
            {
                Operationlogs ol_failed = new Operationlogs();
                ol_failed.Userid      = u.Userid;
                ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_AddNew;
                ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;

                ol_failed.Text = "لم يتم العثور على الفرد: " + frm.Personid; //todo, change it actual person name
                Handler_Operations.Add_New_Operation_Log(ol_failed);
                return(ol_failed);
            }

            string person_mapping_exists = DAL.PostGre_ExScalar("select count(1) from AhwalMapping where Personid = " + frm.Personid);

            if (person_mapping_exists == null || person_mapping_exists == "0")
            {
                Operationlogs ol_failed = new Operationlogs();
                ol_failed.Userid      = u.Userid;
                ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_AddNew;
                ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                ol_failed.Text        = "هذا الفرد موجود مسبقا، لايمكن اضافته مرة اخرى: " + GetPerson.Milnumber.ToString() + " " + GetPerson.Name;
                Handler_Operations.Add_New_Operation_Log(ol_failed);
                return(ol_failed);
            }
            frm.Sortingindex     = 10000;
            frm.Hasfixedcallerid = 0;
            if (GetPerson.Fixedcallerid != null)
            {
                if (GetPerson.Fixedcallerid.Trim() != "" && GetPerson.Fixedcallerid != null)
                {
                    frm.Hasfixedcallerid = Convert.ToByte(1);
                    frm.Callerid         = GetPerson.Fixedcallerid.Trim();
                }
            }
            //frm.sunRiseTimeStamp = null;
            //frm.sunSetTimeStamp = null;
            //frm.lastLandTimeStamp = null;
            //frm.incidentID = null;
            frm.Hasdevices = 0;
            //frm.lastAwayTimeStamp = null;
            //frm.lastComeBackTimeStamp = null;
            frm.Patrolpersonstateid = Handler_AhwalMapping.PatrolPersonState_None;

            string InsQry = "";

            if (frm.Patrolroleid == Handler_AhwalMapping.PatrolRole_CaptainAllSectors || frm.Patrolroleid == Handler_AhwalMapping.PatrolRole_CaptainShift)
            {
                InsQry = "insert into AhwalMapping(ahwalid,sectorid,citygroupid,shiftid,patrolroleid,Personid,hasDevices," +
                         "patrolPersonStateID,sortingIndex,hasFixedCallerID,callerID) values (" +
                         frm.Ahwalid + "," + frm.Sectorid + "," + frm.Citygroupid + "," + frm.Shiftid + "," + frm.Patrolroleid +
                         "," + frm.Personid + "," + frm.Hasdevices + "," + frm.Patrolpersonstateid + "," + frm.Sortingindex + "," + frm.Hasfixedcallerid +
                         ",'" + frm.Callerid + "')";
            }
            else if (frm.Patrolroleid == Handler_AhwalMapping.PatrolRole_CaptainSector || frm.Patrolroleid == Handler_AhwalMapping.PatrolRole_SubCaptainSector)
            {
                InsQry = "insert into AhwalMapping(ahwalid,sectorid,citygroupid,shiftid,patrolroleid,Personid,hasDevices," +
                         "patrolPersonStateID,sortingIndex,hasFixedCallerID,callerID) values (" +
                         frm.Ahwalid + "," + frm.Sectorid + "," + frm.Citygroupid + "," + frm.Shiftid + "," + frm.Patrolroleid +
                         "," + frm.Personid + "," + frm.Hasdevices + "," + frm.Patrolpersonstateid + "," + frm.Sortingindex + "," + frm.Hasfixedcallerid +
                         ",'" + frm.Callerid + "')";
            }
            else if (frm.Patrolroleid == Handler_AhwalMapping.PatrolRole_Associate)
            {
                InsQry = "insert into AhwalMapping(ahwalid,sectorid,citygroupid,shiftid,patrolroleid,Personid,hasDevices," +
                         "patrolPersonStateID,sortingIndex,hasFixedCallerID,callerID) values (" +
                         frm.Ahwalid + "," + frm.Sectorid + "," + frm.Citygroupid + "," + frm.Shiftid + "," + frm.Patrolroleid +
                         "," + frm.Personid + "," + frm.Hasdevices + "," + frm.Patrolpersonstateid + "," + frm.Sortingindex + "," + frm.Hasfixedcallerid +
                         ",'" + frm.Callerid + "')";
            }
            else
            {
                InsQry = "insert into AhwalMapping(ahwalid,sectorid,citygroupid,shiftid,patrolroleid,Personid,hasDevices," +
                         "patrolPersonStateID,sortingIndex,hasFixedCallerID,callerID) values (" +
                         frm.Ahwalid + "," + frm.Sectorid + "," + frm.Citygroupid + "," + frm.Shiftid + "," + frm.Patrolroleid +
                         "," + frm.Personid + "," + frm.Hasdevices + "," + frm.Patrolpersonstateid + "," + frm.Sortingindex + "," + frm.Hasfixedcallerid +
                         ",'" + frm.Callerid + "')";
            }

            int ret = DAL.PostGre_ExNonQry(InsQry);

            Operationlogs ol = new Operationlogs();

            ol.Userid      = u.Userid;
            ol.Operationid = Handler_Operations.Opeartion_Mapping_AddNew;
            ol.Statusid    = Handler_Operations.Opeartion_Status_Success;
            ol.Text        = "تم اضافة الفرد: " + GetPerson.Milnumber.ToString() + " " + GetPerson.Name;
            Handler_Operations.Add_New_Operation_Log(ol);
            return(ol);
        }