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 Operationlogs AddNewMapping(Users u, Ahwalmapping m) //requires AhwalRole { try { //first we have to check if this user is authorized to perform this transaction //if (!_user.isAuthorized(u.Userid, m.Ahwalid, Handler_User.User_Role_Ahwal)) //{ // 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_UnAuthorized; // ol_failed.Text = "المستخدم لايملك صلاحية هذه العمليه"; // _oper.Add_New_Operation_Log(ol_failed); // return ol_failed; //} //we have to check first that this person doesn't exists before in mapping var GetPerson = _context.Persons.FirstOrDefault <Persons>(e => e.Personid.Equals(m.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 = "لم يتم العثور على الفرد: " + m.Personid; //todo, change it actual person name _oper.Add_New_Operation_Log(ol_failed); return(ol_failed); } var person_mapping_exists = _context.Ahwalmapping.FirstOrDefault <Ahwalmapping>(e => e.Personid.Equals(m.Personid)); if (person_mapping_exists != 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 = "هذا الفرد موجود مسبقا، لايمكن اضافته مرة اخرى: " + GetPerson.Milnumber.ToString() + " " + GetPerson.Name; _oper.Add_New_Operation_Log(ol_failed); return(ol_failed); } m.Sortingindex = 10000; //m.Patrolid = null; //m.Handheldid = null; ////force Sector to Public and CityGroup to None for PatrolRole_CaptainAllSectors and PatrolRole_CaptainShift //if (m.Patrolroleid == Core.Handler_AhwalMapping.PatrolRole_CaptainAllSectors || //m.Patrolroleid == Core.Handler_AhwalMapping.PatrolRole_CaptainShift) //{ // m.SectorID = Core.Handler_AhwalMapping.Sector_Public; // m.CityGroupID = Core.Handler_AhwalMapping.CityGroup_None; //} ////force citygroup to be None for Sector Captain and SubCaptain //if (m.Patrolroleid == Core.Handler_AhwalMapping.PatrolRole_CaptainSector || // m.Patrolroleid == Core.Handler_AhwalMapping.PatrolRole_SubCaptainSector) // m.CityGroupID = Core.Handler_AhwalMapping.CityGroup_None; if (GetPerson.Fixedcallerid.Trim() != "" && GetPerson.Fixedcallerid != null) { m.Hasfixedcallerid = Convert.ToByte(1); m.Callerid = GetPerson.Fixedcallerid.Trim(); } //we have to check as well, if we have already 10 people within same citygroup //we cannot add more than 10 per group var totalInSame = _context.Ahwalmapping.Where <Ahwalmapping>(e => e.Ahwalid == m.Ahwalid && e.Shiftid == m.Shiftid && e.Sectorid == m.Sectorid && e.Citygroupid == m.Citygroupid && e.Patrolroleid != Core.Handler_AhwalMapping.PatrolRole_Associate && e.Patrolroleid != Core.Handler_AhwalMapping.PatrolRole_CaptainAllSectors && e.Patrolroleid != Core.Handler_AhwalMapping.PatrolRole_CaptainShift); if (totalInSame != null) { if (totalInSame.Count <Ahwalmapping>() >= 10) { 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 = "لايمكن اضافة اكثر من عشر اشخاص في نفس المنطقة"; _oper.Add_New_Operation_Log(ol_failed); return(ol_failed); } } // m.Sector = _context.Sectors.f; //m.Sunrisetimestamp = null; //m.Sunsettimestamp = null; //m.Lastlandtimestamp = null; //m.Incidentid = null; m.Hasdevices = 0; //m.Lastawaytimestamp = null; //m.Lastcomebacktimestamp = null; m.Patrolpersonstateid = Core.Handler_AhwalMapping.PatrolPersonState_None; //if (m.Sectorid !=null) //{ // m.Sector = _context.Sectors.FirstOrDefault<Sectors>(ec => ec.Sectorid == m.Sectorid); //} //if (m.Citygroupid != null) //{ // m.Citygroup = _context.Citygroups.FirstOrDefault<Citygroups>(ec => ec.Citygroupid == m.Citygroupid); //} //if (m.Shiftid != null) //{ // m.Shift = _context.Shifts.FirstOrDefault<Shifts>(ec => ec.Shiftid == m.Shiftid); //} //if (m.Patrolroleid != null) //{ // m.Patrolrole = _context.Patrolroles.FirstOrDefault<Patrolroles>(ec => ec.Patrolroleid == m.Patrolroleid); //} // m.Patrolpersonstate = _context.Patrolpersonstates.FirstOrDefault<Patrolpersonstates>(ec => ec.Patrolpersonstateid == m.Patrolpersonstateid); /// m.Person = _context.Persons.FirstOrDefault<Persons>(ec => ec.Personid == m.Personid); string InsQry = ""; InsQry = "insert into AhwalMapping(ahwalid,sectorid,citygroupid,shiftid,patrolroleid,personid,hasDevices," + "patrolPersonStateID,sortingIndex,hasFixedCallerID,callerID) values (" + m.Ahwalid + "," + m.Sectorid + "," + m.Citygroupid + "," + m.Shiftid + "," + m.Patrolid + "," + m.Personid + "," + m.Hasdevices + "," + m.Patrolpersonstateid + "," + m.Sortingindex + "," + m.Hasfixedcallerid + ",'" + m.Callerid + "')"; int ret = DAL.PostGre_ExNonQry(InsQry); // _context.Ahwalmapping.Add(m); // _context.SaveChanges(); //time to resort sortingindex // Core.Handler_AhwalMapping.ReSortMappings(); //log it 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; _oper.Add_New_Operation_Log(ol); return(ol); } catch (Exception ex) { 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_UnKnownError; ol_failed.Text = ex.Message; _oper.Add_New_Operation_Log(ol_failed); return(ol_failed); } }
public Operationlogs CheckInPatrolAndHandHeld(Users u, Ahwalmapping m, Patrolcars p, Handhelds h) { try { //first we have to check if this user is authorized to perform this transaction //if (!_user.isAuthorized(u.Userid, p.Ahwalid, Handler_User.User_Role_Ahwal)) //{ // Operationlogs ol_failed = new Operationlogs(); // ol_failed.Userid = u.Userid; // ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_CheckInPatrolAndHandHeld; // ol_failed.Statusid = Handler_Operations.Opeartion_Status_UnAuthorized; // ol_failed.Text = "المستخدم لايملك صلاحية هذه العمليه"; // _oper.Add_New_Operation_Log(ol_failed); // return ol_failed; //} //we have to check first that this person doesn't exists before in mapping var person_mapping_exists = _context.Ahwalmapping.FirstOrDefault <Ahwalmapping>(e => e.Ahwalmappingid.Equals(m.Ahwalmappingid)); if (person_mapping_exists == null) { Operationlogs ol_failed = new Operationlogs(); ol_failed.Userid = u.Userid; ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_CheckInPatrolAndHandHeld; ol_failed.Statusid = Handler_Operations.Opeartion_Status_Failed; ol_failed.Text = "لم يتم العثور على التوزيع"; _oper.Add_New_Operation_Log(ol_failed); return(ol_failed); } var GetPerson = _context.Persons.FirstOrDefault <Persons>(e => e.Personid.Equals(m.Personid)); if (GetPerson == null) { Operationlogs ol_failed = new Operationlogs(); ol_failed.Userid = u.Userid; ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_CheckInPatrolAndHandHeld; ol_failed.Statusid = Handler_Operations.Opeartion_Status_Failed; ol_failed.Text = "لم يتم العثور على الفرد: " + m.Personid; //todo, change it actual person name _oper.Add_New_Operation_Log(ol_failed); return(ol_failed); } if (Convert.ToBoolean(person_mapping_exists.Hasdevices)) { Operationlogs ol_failed = new Operationlogs(); ol_failed.Userid = u.Userid; ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_CheckInPatrolAndHandHeld; ol_failed.Statusid = Handler_Operations.Opeartion_Status_Failed; ol_failed.Text = "هذا المستخدم يملك حاليا اجهزة"; _oper.Add_New_Operation_Log(ol_failed); return(ol_failed); } person_mapping_exists.Patrolid = p.Patrolid; person_mapping_exists.Handheldid = h.Handheldid; person_mapping_exists.Patrolpersonstateid = Core.Handler_AhwalMapping.PatrolPersonState_SunRise; person_mapping_exists.Sunrisetimestamp = DateTime.Now; person_mapping_exists.Sunsettimestamp = null;//we have to reset this time person_mapping_exists.Hasdevices = Convert.ToByte(1); person_mapping_exists.Laststatechangetimestamp = DateTime.Now; _context.SaveChanges(); //log it //we have to add this record in checkIn and CheckOut Table var PatrolCheckInLog = new Patrolcheckinout(); PatrolCheckInLog.Checkinoutstateid = Core.Handler_AhwalMapping.CheckInState; PatrolCheckInLog.Timestamp = DateTime.Now; PatrolCheckInLog.Personid = m.Personid; PatrolCheckInLog.Patrolid = p.Patrolid; _context.Patrolcheckinout.Add(PatrolCheckInLog); var HandHeldCheckInLog = new Handheldscheckinout(); HandHeldCheckInLog.Checkinoutstateid = Core.Handler_AhwalMapping.CheckInState; HandHeldCheckInLog.Timestamp = DateTime.Now; HandHeldCheckInLog.Personid = m.Personid; HandHeldCheckInLog.Handheldid = h.Handheldid; _context.Handheldscheckinout.Add(HandHeldCheckInLog); _context.SaveChanges(); //record this in personstatechangelog var personStateLog = new Patrolpersonstatelog(); personStateLog.Userid = u.Userid; personStateLog.Patrolpersonstateid = Core.Handler_AhwalMapping.PatrolPersonState_SunRise; personStateLog.Timestamp = DateTime.Now; personStateLog.Personid = m.Personid; LogPersonStateChange(personStateLog); Operationlogs ol = new Operationlogs(); ol.Userid = u.Userid; ol.Operationid = Handler_Operations.Opeartion_Mapping_CheckInPatrolAndHandHeld; ol.Statusid = Handler_Operations.Opeartion_Status_Success; ol.Text = "تم تسليم الفرد: " + GetPerson.Milnumber.ToString() + " " + GetPerson.Name + " الدورية رقم: " + p.Platenumber + " والجهاز رقم: " + h.Serial; _oper.Add_New_Operation_Log(ol); return(ol); } catch (Exception ex) { Operationlogs ol_failed = new Operationlogs(); ol_failed.Userid = u.Userid; ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_CheckOutPatrolAndHandHeld; ol_failed.Statusid = Handler_Operations.Opeartion_Status_UnKnownError; ol_failed.Text = ex.Message; _oper.Add_New_Operation_Log(ol_failed); return(ol_failed); } }
public Operationlogs HandOver_Incident_To_Person(Users u, Ahwalmapping m, Incidents i) { try { //first we have to check if this Users is authorized to perform this transaction //Usersrolesmap permisson_esists = _context.Usersrolesmap.FirstOrDefault(r => r.Userid == u.Userid && r.Userroleid == Core.Handler_User.User_Role_Ops); //if (permisson_esists == null) //{ // Operationlogs ol_failed = new Operationlogs(); // ol_failed.Userid = u.Userid; // ol_failed.Operationid = Handler_Operations.Opeartion_Incidents_HandOverIncident; // ol_failed.Statusid = Handler_Operations.Opeartion_Status_UnAuthorized; // ol_failed.Text = "المستخدم لايملك صلاحية هذه العمليه"; // _oper.Add_New_Operation_Log(ol_failed); // return ol_failed; //} var personmapping = _context.Ahwalmapping.FirstOrDefault <Ahwalmapping>(a => a.Ahwalmappingid == m.Ahwalmappingid); if (personmapping == null) { Operationlogs ol_failed = new Operationlogs(); ol_failed.Userid = u.Userid; ol_failed.Operationid = Handler_Operations.Opeartion_Incidents_HandOverIncident; ol_failed.Statusid = Handler_Operations.Opeartion_Status_UnAuthorized; ol_failed.Text = "لم يتم العثور على التوزيع رقم: " + m.Ahwalmappingid.ToString(); _oper.Add_New_Operation_Log(ol_failed); return(ol_failed); } var Incidents = _context.Incidents.FirstOrDefault <Incidents>(a => a.Incidentid == i.Incidentid); if (Incidents == null) { Operationlogs ol_failed = new Operationlogs(); ol_failed.Userid = u.Userid; ol_failed.Operationid = Handler_Operations.Opeartion_Incidents_HandOverIncident; ol_failed.Statusid = Handler_Operations.Opeartion_Status_UnAuthorized; ol_failed.Text = "لم يتم العثور على البلاغ رقم: " + i.Incidentid.ToString(); _oper.Add_New_Operation_Log(ol_failed); return(ol_failed); } //we have to check the state of the person, we cannot hand over Incidents to wrong state if (personmapping.Patrolpersonstateid != Core.Handler_AhwalMapping.PatrolPersonState_SunRise && personmapping.Patrolpersonstateid != Core.Handler_AhwalMapping.PatrolPersonState_Sea && personmapping.Patrolpersonstateid != Core.Handler_AhwalMapping.PatrolPersonState_Back && personmapping.Patrolpersonstateid != Core.Handler_AhwalMapping.PatrolPersonState_WalkingPatrol && personmapping.Patrolpersonstateid != Core.Handler_AhwalMapping.PatrolPersonState_BackFromWalking) { Operationlogs ol_failed = new Operationlogs(); ol_failed.Userid = u.Userid; ol_failed.Operationid = Handler_Operations.Opeartion_Incidents_HandOverIncident; ol_failed.Statusid = Handler_Operations.Opeartion_Status_UnAuthorized; ol_failed.Text = "الدورية في حالة لاتسمح باستلام بلاغ" + i.Incidentid.ToString(); _oper.Add_New_Operation_Log(ol_failed); return(ol_failed); } //update mapping to show that person has an Incidents personmapping.Incidentid = Incidents.Incidentid; Incidents.Lastupdate = DateTime.Now; Incidents.Incidentstateid = Core.Handler_Incidents.Incident_State_HasComments; var newIncidentComment = new Incidentscomments(); newIncidentComment.Incidentid = Incidents.Incidentid; newIncidentComment.Userid = u.Userid; newIncidentComment.Text = "قام بتسليم البلاغ للدورية صاحبة النداء: " + m.Callerid.ToString(); newIncidentComment.Timestamp = DateTime.Now; _context.Incidentscomments.Add(newIncidentComment); _context.SaveChanges(); AddNewIncidentViewForAllExceptOriginalPoster(u, i); Operationlogs ol_success = new Operationlogs(); ol_success.Userid = u.Userid; ol_success.Operationid = Handler_Operations.Opeartion_Incidents_HandOverIncident; ol_success.Statusid = Handler_Operations.Opeartion_Status_Success; ol_success.Text = "ناجح" + i.Incidentsourceid.ToString(); _oper.Add_New_Operation_Log(ol_success); return(ol_success); } catch (Exception ex) { Operationlogs ol_failed = new Operationlogs(); ol_failed.Userid = u.Userid; ol_failed.Operationid = Handler_Operations.Opeartion_Incidents_HandOverIncident; ol_failed.Statusid = Handler_Operations.Opeartion_Status_UnKnownError; ol_failed.Text = ex.Message; _oper.Add_New_Operation_Log(ol_failed); return(ol_failed); } Operationlogs ol = new Operationlogs(); ol.Userid = u.Userid; ol.Operationid = Handler_Operations.Opeartion_Incidents_HandOverIncident; ol.Statusid = Handler_Operations.Opeartion_Status_Success; ol.Text = "تم تسليم الدورية صاحبة النداء: " + m.Callerid.ToString() + " البلاغ رقم: " + i.Incidentid.ToString(); _oper.Add_New_Operation_Log(ol); return(ol); }
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); }
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); }
public IActionResult PostAddAhwalMapping([FromBody] JObject RqHdr) { var selectedRole = Newtonsoft.Json.JsonConvert.DeserializeObject <string>(RqHdr["PatrolRoleId"].ToString(), new Newtonsoft.Json.JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore }); var personSelection = Newtonsoft.Json.JsonConvert.DeserializeObject <string>(RqHdr["Milnumber"].ToString(), new Newtonsoft.Json.JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore }); var uiSelShiftId = Newtonsoft.Json.JsonConvert.DeserializeObject <string>(RqHdr["ShiftId"].ToString(), new Newtonsoft.Json.JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore }); var uiSelSectorId = Newtonsoft.Json.JsonConvert.DeserializeObject <string>(RqHdr["SectorId"].ToString(), new Newtonsoft.Json.JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore }); var uiSelCityGroupId = Newtonsoft.Json.JsonConvert.DeserializeObject <string>(RqHdr["CityGroupId"].ToString(), new Newtonsoft.Json.JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore }); //var uiSelAhwalMappingID = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(RqHdr["AhwalMappingID"].ToString(), new Newtonsoft.Json.JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore }); var uiSelAssociateAhwalMappingID = Newtonsoft.Json.JsonConvert.DeserializeObject <string>(RqHdr["AssociateAhwalMappingID"].ToString(), new Newtonsoft.Json.JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore }); string responsemsg = ""; if (selectedRole == null) { responsemsg = "يرجى اختيار المسؤولية"; return(Ok(responsemsg)); } if (personSelection == null) { responsemsg = "يرجى اختيار الفرد"; return(Ok(responsemsg)); } Users user = new Users(); user.Userid = Convert.ToInt32(RqHdr["userid"]); var personMilNumber = Convert.ToInt64(personSelection.ToString()); var person = _person.GetPersonForUserForRole(user, personMilNumber, Handler_User.User_Role_Ahwal); if (person == null) { responsemsg = "لم يتم العثور على الفرد"; return(Ok(responsemsg)); } var m = new Ahwalmapping(); if (Convert.ToInt64(selectedRole) == Handler_AhwalMapping.PatrolRole_CaptainAllSectors || Convert.ToInt64(selectedRole) == Handler_AhwalMapping.PatrolRole_CaptainShift) { var shiftSelection = uiSelShiftId; if (shiftSelection == null) { responsemsg = "يرجى اختيار الشفت"; return(Ok(responsemsg)); } var personID = person.Personid; m.Ahwalid = person.Ahwalid; m.Sectorid = Core.Handler_AhwalMapping.Sector_Public; //the first result of an ahwal will alway be the generic public sector var cityID = _context.Citygroups.FirstOrDefault <Citygroups>(ec => ec.Ahwalid == person.Ahwalid); m.Citygroupid = cityID.Citygroupid;// Core.Handler_AhwalMapping.CityGroup_Sector_Public_CityGroupNone; m.Shiftid = Convert.ToInt16(shiftSelection.ToString()); m.Patrolid = Convert.ToInt16(selectedRole); m.Personid = personID; Operationlogs result; //if (Request.Form["AhwalMappingAddMethod"] == "UPDATE") //{ // m.Ahwalmappingid = Convert.ToInt64(uiSelAhwalMappingID); // result = _ahwalmapping.UpDateMapping(user, m); //} //else //{ result = _ahwalmapping.AddNewMapping(user, m); //} responsemsg = result.Text; } else if (Convert.ToInt64(selectedRole) == Handler_AhwalMapping.PatrolRole_CaptainSector || Convert.ToInt64(selectedRole) == Handler_AhwalMapping.PatrolRole_SubCaptainSector) { var shiftSelection = uiSelShiftId; if (shiftSelection == null) { responsemsg = "يرجى اختيار الشفت"; return(Ok(responsemsg)); } var personID = person.Personid; m.Ahwalid = person.Ahwalid; var sectorSelection = uiSelSectorId; if (sectorSelection == null) { responsemsg = "يرجى اختيار القطاع"; return(Ok(responsemsg)); } m.Sectorid = Convert.ToInt16(uiSelSectorId.ToString()); //the first result of an ahwal and sector, will alwayy be considered as the public sector var cityID = _context.Citygroups.FirstOrDefault <Citygroups>(ec => ec.Ahwalid == person.Ahwalid && ec.Sectorid == m.Sectorid); m.Citygroupid = cityID.Citygroupid;// Core.Handler_AhwalMapping.CityGroup_Sector_Public_CityGroupNone; m.Shiftid = Convert.ToInt16(uiSelShiftId.ToString()); m.Patrolid = Convert.ToInt16(selectedRole); m.Personid = personID; Operationlogs result; //if (Request.Form["AhwalMappingAddMethod"] == "UPDATE") //{ // m.Ahwalmappingid = Convert.ToInt64(uiSelAhwalMappingID); // result = _ahwalmapping.UpDateMapping(user, m); //} //else //{ result = _ahwalmapping.AddNewMapping(user, m); // } responsemsg = result.Text; } else if (Convert.ToInt64(selectedRole) == Core.Handler_AhwalMapping.PatrolRole_Associate) { var associateSelectionmappingID = uiSelAssociateAhwalMappingID; if (associateSelectionmappingID == null) { responsemsg = "يرجى اختيار المرافق"; return(Ok(responsemsg)); } var ahwalMappingForAssociate = _ahwalmapping.GetMappingByID(user, Convert.ToInt64(associateSelectionmappingID.ToString()), Core.Handler_User.User_Role_Ahwal); if (ahwalMappingForAssociate != null) { var personID = person.Personid; if (personID == ahwalMappingForAssociate.Personid) { responsemsg = "المرافق نفس الفرد، ماهذا ؟؟؟؟"; return(Ok(responsemsg)); } m.Ahwalid = ahwalMappingForAssociate.Ahwalid; m.Personid = personID; m.Associtatepersonid = ahwalMappingForAssociate.Personid; m.Sectorid = ahwalMappingForAssociate.Sectorid; m.Citygroupid = ahwalMappingForAssociate.Citygroupid; m.Shiftid = ahwalMappingForAssociate.Shiftid; m.Patrolid = Convert.ToInt16(selectedRole); Operationlogs result; //if (Request.Form["AhwalMappingAddMethod"] == "UPDATE") //{ // m.Ahwalmappingid = Convert.ToInt64(uiSelAhwalMappingID); // result = _ahwalmapping.UpDateMapping(user, m); //} //else //{ result = _ahwalmapping.AddNewMapping(user, m); // } responsemsg = result.Text; } } else { var shiftSelection = uiSelShiftId; if (shiftSelection == null) { responsemsg = "يرجى اختيار الشفت"; return(Ok(responsemsg)); } var personID = person.Personid; m.Ahwalid = person.Ahwalid; var sectorSelection = uiSelSectorId; if (sectorSelection == null) { responsemsg = "يرجى اختيار القطاع"; return(Ok(responsemsg)); } var citySelection = uiSelCityGroupId; if (citySelection == null) { responsemsg = "يرجى اختيار المنطقة"; return(Ok(responsemsg)); } m.Sectorid = Convert.ToInt16(uiSelSectorId.ToString()); m.Citygroupid = Convert.ToInt16(uiSelCityGroupId.ToString()); m.Shiftid = Convert.ToInt16(uiSelShiftId.ToString()); m.Patrolid = Convert.ToInt16(selectedRole); m.Personid = personID; Operationlogs result; //if (Request.Form["AhwalMappingAddMethod"] == "UPDATE") //{ // m.Ahwalmappingid = Convert.ToInt64(uiSelAhwalMappingID); // result = _ahwalmapping.UpDateMapping(user, m); //} //else //{ result = _ahwalmapping.AddNewMapping(user, m); // } responsemsg = result.Text; } return(Ok(responsemsg)); }