Exemple #1
0
        public int PostUpDateAhwalMapping([FromBody] AhwalMapping frm)
        {
            int    ret       = 0;
            string UpdateQry = "";

            UpdateQry = "update AhwalMapping set ahwalid = " + frm.ahwalID + ",sectorid=" + frm.sectorID + ",citygroupid=" + frm.cityGroupID + ",shiftid=" + frm.shiftID + ",patrolroleid=" + frm.patrolRoleID + ",personid=" + frm.personID + " where ahwalmappingid = " + frm.ahwalMappingID;
            ret       = DAL.PostGre_ExNonQry(UpdateQry);
            return(ret);
        }
        public OperationLog 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)
            {
                OperationLog ol_failed = new OperationLog();
                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)
            {
                OperationLog ol_failed = new OperationLog();
                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))
            {
                OperationLog ol_failed = new OperationLog();
                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);
            }

            OperationLog ol  = new OperationLog();
            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);
        }
        public OperationLog PostAddAhwalMapping([FromBody] JObject data)
        {
            AhwalMapping frm = Newtonsoft.Json.JsonConvert.DeserializeObject <AhwalMapping>(data["ahwalmappingobj"].ToString(), new Newtonsoft.Json.JsonSerializerSettings {
                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            });
            User u = data["userobj"].ToObject <User>();
            //  GetPerson = "";
            // string ol_failed = "";
            //OperationLog ol = new OperationLog();
            //we have to check first that this person doesn't exists before in mapping
            Persons GetPerson = GetPersonById(frm.personID);

            if (GetPerson == null)
            {
                OperationLog ol_failed = new OperationLog();
                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")
            {
                OperationLog ol_failed = new OperationLog();
                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);

            OperationLog ol = new OperationLog();

            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);
        }