public ActionResult PostCloseIncident([FromBody] JObject RqHdr)
        {
            var incidentid = (Newtonsoft.Json.JsonConvert.DeserializeObject <string>(RqHdr["incidentid"].ToString(), new Newtonsoft.Json.JsonSerializerSettings {
                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            }));
            var userid     = (Newtonsoft.Json.JsonConvert.DeserializeObject <Int16>(RqHdr["userid"].ToString(), new Newtonsoft.Json.JsonSerializerSettings {
                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            }));


            var incident = _context.Incidents.FirstOrDefault(em => em.Incidentid == Convert.ToInt64(incidentid));

            //Session["CommentsIncidentID"] = incident.IncidentID;
            //if incident already closed, just ignore this stupid user
            if (incident.Incidentstateid == Core.Handler_Incidents.Incident_State_Closed)
            {
                return(Ok(null));
            }
            Users user = new Users();

            user.Userid = userid;
            Operationlogs _ol = new Operationlogs();

            _ol = _inc.Close_Incident(user, incident);
            return(Ok(_ol.Text));
        }
        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));
        }
        //all functions here require Ahwal Permssion
        public Operationlogs Add_Incident(Users u, Incidents i) //this transaction requires User_Role_Ahwal Permisson on this AhwalID
        {
            try
            {
                //first we have to check if this user 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_AddNew;
                    ol_failed.Statusid    = Handler_Operations.Opeartion_Status_UnAuthorized;
                    ol_failed.Text        = "المستخدم لايملك صلاحية هذه العمليه";
                    _oper.Add_New_Operation_Log(ol_failed);
                    return(ol_failed);
                }
                i.Userid     = u.Userid;
                i.Timestamp  = DateTime.Now;
                i.Lastupdate = DateTime.Now;
                _context.Incidents.Add(i);
                //by default,we will add new comment for a new incidet,this will help later in the incidents dedicated page, that each incident at least has one comment

                _context.SaveChanges();
                //still, the incident status will be new, but with this we make sure that each incident at least has one comment
                var newIncidentComment = new Incidentscomments();
                newIncidentComment.Incidentid = i.Incidentid;
                newIncidentComment.Userid     = u.Userid;
                newIncidentComment.Text       = "قام باضافة البلاغ";
                newIncidentComment.Timestamp  = DateTime.Now;
                _context.Incidentscomments.Add(newIncidentComment);
                _context.SaveChanges();
                //add it incidentview
                AddNewIncidentViewForAllExceptOriginalPoster(u, i);

                //create the opeartion log for it
            }
            catch (Exception ex)
            {
                Operationlogs ol_failed = new Operationlogs();
                ol_failed.Userid      = u.Userid;
                ol_failed.Operationid = Handler_Operations.Opeartion_Incidents_AddNew;
                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_AddNew;
            ol.Statusid    = Handler_Operations.Opeartion_Status_Success;
            ol.Text        = "تم اضافة البلاغ رقم: " + i.Incidentid.ToString();
            _oper.Add_New_Operation_Log(ol);
            return(ol);
        }
        //all functions here require Ahwal Permssion
        public Operationlogs Add_HandHeldr(Users u, Handhelds h) //this transaction requires User_Role_Maintenance Permisson on this AhwalID
        {
            try
            {
                //first we have to check if this Users is authorized to perform this transaction
                //if (!_user.isAuthorized(u.Userid, h.Ahwalid, Handler_User.User_Role_Maintenance))
                //{
                //    Operationlogs ol_failed = new Operationlogs();
                //    ol_failed.Userid = u.Userid;
                //    ol_failed.Operationid  = Handler_Operations.Opeartion_AddHandHeld;
                //    ol_failed.Statusid = Handler_Operations.Opeartion_Status_UnAuthorized;
                //    ol_failed.Text = "المستخدم لايملك صلاحية هذه العمليه";
                //    _oper.Add_New_Operation_Log(ol_failed);
                //    return ol_failed;
                //}
                //next we need to search if there is a Handhelds with same serial
                Handhelds HandHeld_exists = _context.Handhelds.FirstOrDefault(e => e.Serial.Equals(h.Serial));
                if (HandHeld_exists != null)
                {
                    Operationlogs ol_failed = new Operationlogs();
                    ol_failed.Userid      = u.Userid;
                    ol_failed.Operationid = Handler_Operations.Opeartion_AddHandHeld;
                    ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                    ol_failed.Text        = "يوجد لاسلكي بنفس رقم : " + h.Serial;
                    _oper.Add_New_Operation_Log(ol_failed);
                    return(ol_failed);
                }
                h.Barcode = "HAN" + h.Serial;
                //  var handhelds = _context.Set<Handhelds>();
                //  handhelds.Add(h);

                _context.Handhelds.Add(h);
                _context.SaveChanges();
            }

            catch (Exception ex)
            {
                Operationlogs ol_failed = new Operationlogs();
                ol_failed.Userid      = u.Userid;
                ol_failed.Operationid = Handler_Operations.Opeartion_AddHandHeld;
                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_AddHandHeld;
            ol.Statusid    = Handler_Operations.Opeartion_Status_Success;
            ol.Text        = "تم اضافة لاسلكي: " + h.Serial;
            _oper.Add_New_Operation_Log(ol);
            return(ol);
        }
Пример #5
0
        public Operationlogs Delete_IncidentType(int incidenttypeid, Users u)
        {
            try
            {
                //first we have to check if this user 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_IncidentsTypes_AddNew;
                    ol_failed.Statusid    = Handler_Operations.Opeartion_Status_UnAuthorized;
                    ol_failed.Text        = "المستخدم لايملك صلاحية هذه العمليه";
                    _oper.Add_New_Operation_Log(ol_failed);
                    return(ol_failed);
                }

                if (incidenttypeid > 0)
                {
                    Incidentstypes it = _context.Incidentstypes.Where(i => i.Incidenttypeid == incidenttypeid).FirstOrDefault();
                    if (it == null)
                    {
                        Operationlogs ol_failed = new Operationlogs();
                        ol_failed.Userid      = u.Userid;
                        ol_failed.Operationid = Handler_Operations.Opeartion_IncidentsTypes_AddNew;
                        ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                        ol_failed.Text        = "Could not find the communication with the id";
                        _oper.Add_New_Operation_Log(ol_failed);
                        return(ol_failed);
                    }
                    _context.Incidentstypes.Remove(it);
                    _context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Operationlogs ol_failed = new Operationlogs();
                ol_failed.Userid      = u.Userid;
                ol_failed.Operationid = Handler_Operations.Opeartion_IncidentsTypes_AddNew;
                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_IncidentsTypes_AddNew;
            ol.Statusid    = Handler_Operations.Opeartion_Status_Success;
            ol.Text        = "تم اضافة البلاغ رقم: " + incidenttypeid.ToString();
            _oper.Add_New_Operation_Log(ol);
            return(ol);
        }
Пример #6
0
        public string Add_New_Comment(Users u, Incidentscomments c)//this transaction requires User_Role_Ahwal Permisson on this AhwalID
        {
            try
            {
                //first we have to check if this user 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_NewComment;
                    ol_failed.Statusid    = Handler_Operations.Opeartion_Status_UnAuthorized;
                    ol_failed.Text        = "المستخدم لايملك صلاحية هذه العمليه";
                    _oper.Add_New_Operation_Log(ol_failed);
                    return(ol_failed.Text);
                }
                c.Userid            = u.Userid;
                c.Timestamp         = DateTime.Now;
                c.Incidentcommentid = 0;
                _context.Incidentscomments.Add(c);

                //we have to change the state of the incident now
                var incident = _context.Incidents.FirstOrDefault <Incidents>(a => a.Incidentid == c.Incidentid);
                incident.Incidentstateid = Core.Handler_Incidents.Incident_State_HasComments;
                incident.Lastupdate      = DateTime.Now;
                _context.SaveChanges();
                AddNewIncidentViewForAllExceptOriginalPoster(u, incident);
                return("تم إدخاله بنجاح");
            }
            catch (Exception ex)
            {
                Operationlogs ol_failed = new Operationlogs();
                ol_failed.Userid      = u.Userid;
                ol_failed.Operationid = Handler_Operations.Opeartion_Incidents_NewComment;
                ol_failed.Statusid    = Handler_Operations.Opeartion_Status_UnKnownError;
                ol_failed.Text        = ex.Message;
                _oper.Add_New_Operation_Log(ol_failed);
                return(ol_failed.Text);
            }
            Operationlogs ol = new Operationlogs();

            ol.Userid      = u.Userid;
            ol.Operationid = Handler_Operations.Opeartion_Incidents_NewComment;
            ol.Statusid    = Handler_Operations.Opeartion_Status_Success;
            ol.Text        = "تم اضافة تعليق جديد رقم: " + c.Incidentcommentid.ToString() + " على البلاغ رقم: " + c.Incidentid;
            _oper.Add_New_Operation_Log(ol);
            return(ol.Text);
        }
Пример #7
0
 public bool Add_New_Operation_Log(Operationlogs ol)
 {
     try
     {
         // DataClassesDataContext db = new DataClassesDataContext(Handler_Global.connectString);
         ol.Timestamp = DateTime.Now; //Dont ever use autogenerated, it sucks and create issues
         _context.Operationlogs.Add(ol);
         _context.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         // MessageBox.Show(ex.Message);
     }
     return(false);
 }
Пример #8
0
 public static bool Add_New_Operation_Log(Operationlogs ol)
 {
     try
     {
         // DataClassesDataContext db = new DataClassesDataContext(Handler_Global.connectString);
         //ol.TImeStamp = DateTime.Now; //Dont ever use autogenerated, it sucks and create issues
         //db.OperationLogs.InsertOnSubmit(ol);
         //db.SubmitChanges();
         return(true);
     }
     catch (Exception ex)
     {
         // MessageBox.Show(ex.Message);
     }
     return(false);
 }
Пример #9
0
        public Operationlogs DeleteAhwalMapping([FromQuery] int ahwalMappingID, [FromQuery] int Userid)
        {
            //string ol_label = "";
            Operationlogs ol     = new Operationlogs();
            int           ret    = 0;
            string        DelQry = "";

            DelQry = "delete from AhwalMapping where ahwalMappingID = " + ahwalMappingID;
            ret    = DAL.PostGre_ExNonQry(DelQry);
            if (ret > 0)
            {
                ol.Userid      = Userid;
                ol.Operationid = Handler_Operations.Opeartion_Mapping_Remove;
                ol.Statusid    = Handler_Operations.Opeartion_Status_Success;
                ol.Text        = "تم حذف الفرد ";
                return(ol);
            }
            ol.Statusid = Handler_Operations.Opeartion_Status_Failed;
            ol.Text     = "Failed";
            return(ol);
        }
Пример #10
0
        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);
        }
Пример #12
0
        public Operationlogs DeleteMapping(Users u, long mappingID)
        {
            try
            {
                var result = _context.Ahwalmapping.FirstOrDefault <Ahwalmapping>(e => e.Ahwalmappingid == mappingID);
                if (result == null)
                {
                    Operationlogs ol_failed = new Operationlogs();
                    ol_failed.Userid      = u.Userid;
                    ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_Update;
                    ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                    ol_failed.Text        = "لم يتم العثور على التوزيع: " + mappingID.ToString();
                    _oper.Add_New_Operation_Log(ol_failed);
                    return(ol_failed);
                }
                //first we have to check if this user is authorized to perform this transaction
                if (!_user.isAuthorized(u.Userid, result.Ahwalid, Handler_User.User_Role_Ahwal))
                {
                    Operationlogs ol_failed = new Operationlogs();
                    ol_failed.Userid      = u.Userid;
                    ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_Remove;
                    ol_failed.Statusid    = Handler_Operations.Opeartion_Status_UnAuthorized;
                    ol_failed.Text        = "المستخدم لايملك صلاحية هذه العمليه";
                    _oper.Add_New_Operation_Log(ol_failed);
                    return(ol_failed);
                }

                var GetPerson = _context.Persons.FirstOrDefault <Persons>(e => e.Personid.Equals(result.Personid));
                if (GetPerson == null)
                {
                    Operationlogs ol_failed = new Operationlogs();
                    ol_failed.Userid      = u.Userid;
                    ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_Update;
                    ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                    ol_failed.Text        = "لم يتم العثور على الفرد: " + result.Personid; //todo, change it actual person name
                    _oper.Add_New_Operation_Log(ol_failed);
                    return(ol_failed);
                }
                //if he has devices, we cannot remove him

                //I'll disable this check for now, we still can delete a user even if he has devices
                if (Convert.ToBoolean(result.Hasdevices))
                {
                    Operationlogs ol_failed = new Operationlogs();
                    ol_failed.Userid      = u.Userid;
                    ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_Remove;
                    ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                    ol_failed.Text        = ":هذا الفرد لم يسلم الاجهزة " + GetPerson.Milnumber + " " + GetPerson.Name;
                    _oper.Add_New_Operation_Log(ol_failed);
                    return(ol_failed);
                }
                //if he has someone associate to him,we cannot delete him, must delete the associate first

                var hasAssociate = _context.Ahwalmapping.FirstOrDefault <Ahwalmapping>(e => e.Associtatepersonid == result.Personid);
                if (hasAssociate != null)
                {
                    Operationlogs ol_failed = new Operationlogs();
                    ol_failed.Userid      = u.Userid;
                    ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_Remove;
                    ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                    ol_failed.Text        = "هذا المستخدم لديه مرافق" + GetPerson.Milnumber + " " + GetPerson.Name;//TODO: Add associate details
                    _oper.Add_New_Operation_Log(ol_failed);
                    return(ol_failed);
                }
                _context.Ahwalmapping.Remove(result);

                _context.SaveChanges();

                //we need to resort
                //  Core.Handler_AhwalMapping.ReSortMappings();
                Operationlogs ol = new Operationlogs();
                ol.Userid      = u.Userid;
                ol.Operationid = Handler_Operations.Opeartion_Mapping_Remove;
                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_Remove;
                ol_failed.Statusid    = Handler_Operations.Opeartion_Status_UnKnownError;
                ol_failed.Text        = ex.Message;
                _oper.Add_New_Operation_Log(ol_failed);
                return(ol_failed);
            }
        }
Пример #13
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);
        }
Пример #14
0
        public Operationlogs Close_Incident(Users u, Incidents i)//this transaction requires User_Role_Ahwal Permisson on this AhwalID
        {
            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_Close;
                    ol_failed.Statusid    = Handler_Operations.Opeartion_Status_UnAuthorized;
                    ol_failed.Text        = "المستخدم لايملك صلاحية هذه العمليه";
                    _oper.Add_New_Operation_Log(ol_failed);
                    return(ol_failed);
                }
                //next we need to search if there is a Users with same milnumber
                Incidents incident_exists = _context.Incidents.FirstOrDefault(e => e.Incidentid.Equals(i.Incidentid));
                if (incident_exists == null)
                {
                    Operationlogs ol_failed = new Operationlogs();
                    ol_failed.Userid      = u.Userid;
                    ol_failed.Operationid = Handler_Operations.Opeartion_Incidents_Close;
                    ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                    ol_failed.Text        = "لم يتم العثور على البلاغ رقم: " + i.Incidentid.ToString();
                    _oper.Add_New_Operation_Log(ol_failed);
                    return(ol_failed);
                }
                //we have to check first if there is someone holding this Incidents,so we automatically release the poor guy
                var someonewithThisIncident = _context.Ahwalmapping.FirstOrDefault <Ahwalmapping>(a => a.Incidentid == incident_exists.Incidentid);
                if (someonewithThisIncident != null)
                {
                    someonewithThisIncident.Incidentid = null;
                    incident_exists.Lastupdate         = DateTime.Now;
                    var newIncidentCommentCancel = new Incidentscomments();
                    newIncidentCommentCancel.Incidentid = incident_exists.Incidentid;
                    newIncidentCommentCancel.Userid     = u.Userid;
                    newIncidentCommentCancel.Text       = "قام بالغاء تسليم البلاغ للدورية صاحبة النداء: " + someonewithThisIncident.Callerid.ToString();
                    newIncidentCommentCancel.Timestamp  = DateTime.Now;
                    _context.Incidentscomments.Add(newIncidentCommentCancel);
                    _context.SaveChanges();
                }
                incident_exists.Incidentstateid = Core.Handler_Incidents.Incident_State_Closed;
                incident_exists.Lastupdate      = DateTime.Now;
                _context.SaveChanges();
                //again will add a comment for this
                //create the opeartion log for it
                var newIncidentComment = new Incidentscomments();
                newIncidentComment.Incidentid = incident_exists.Incidentid;
                newIncidentComment.Userid     = u.Userid;
                newIncidentComment.Text       = "قام باغلاق البلاغ ";
                newIncidentComment.Timestamp  = DateTime.Now;
                _context.Incidentscomments.Add(newIncidentComment);
                _context.SaveChanges();
                //add this to incidentview
                AddNewIncidentViewForAllExceptOriginalPoster(u, i);
            }
            catch (Exception ex)
            {
                Operationlogs ol_failed = new Operationlogs();
                ol_failed.Userid      = u.Userid;
                ol_failed.Operationid = Handler_Operations.Opeartion_Incidents_Close;
                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_Close;
            ol.Statusid    = Handler_Operations.Opeartion_Status_Success;
            ol.Text        = "قام باغلاق البلاغ: " + i.Incidentid.ToString();
            _oper.Add_New_Operation_Log(ol);
            return(ol);
        }
Пример #15
0
        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);
            }
        }
Пример #16
0
        public Operationlogs Ahwal_ChangePersonState(Users u, long mappingID, Patrolpersonstates s)
        {
            try
            {
                //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(mappingID));
                if (person_mapping_exists == null)
                {
                    Operationlogs ol_failed = new Operationlogs();
                    ol_failed.Userid      = u.Userid;
                    ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_Ahwal_ChangePersonState;
                    ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                    ol_failed.Text        = "لم يتم العثور على التوزيع";
                    _oper.Add_New_Operation_Log(ol_failed);
                    return(ol_failed);
                }
                //a bit different here, for Ahwalmapping, allowed states are only for sick,leave,sunrise,sunset
                int[] allowedState = { Core.Handler_AhwalMapping.PatrolPersonState_SunRise,
                                       Core.Handler_AhwalMapping.PatrolPersonState_SunSet,
                                       Core.Handler_AhwalMapping.PatrolPersonState_Off,
                                       Core.Handler_AhwalMapping.PatrolPersonState_Sick,
                                       Core.Handler_AhwalMapping.PatrolPersonState_Absent };
                //first we have to check if this user is authorized to perform this transaction
                //if (!_user.isAuthorized(u.Userid, person_mapping_exists.Ahwalid, Handler_User.User_Role_Ahwal)
                //    && !allowedState.Contains(s.Patrolpersonstateid))
                //{
                //    Operationlogs ol_failed = new Operationlogs();
                //    ol_failed.Userid = u.Userid;
                //    ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_Ahwal_ChangePersonState;
                //    ol_failed.Statusid = Handler_Operations.Opeartion_Status_UnAuthorized;
                //    ol_failed.Text = "المستخدم لايملك صلاحية هذه العمليه";
                //    _oper.Add_New_Operation_Log(ol_failed);
                //    return ol_failed;
                //}

                var GetPerson = _context.Persons.FirstOrDefault <Persons>(e => e.Personid.Equals(person_mapping_exists.Personid));
                if (GetPerson == null)
                {
                    Operationlogs ol_failed = new Operationlogs();
                    ol_failed.Userid      = u.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
                    _oper.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      = u.Userid;
                    ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_Ahwal_ChangePersonState;
                    ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                    ol_failed.Text        = "هذا المستخدم يملك حاليا اجهزة";
                    _oper.Add_New_Operation_Log(ol_failed);
                    return(ol_failed);
                }

                //in ahwal mapping, we can change associate person state to sick, off,leave
                person_mapping_exists.Patrolpersonstateid      = s.Patrolpersonstateid;
                person_mapping_exists.Laststatechangetimestamp = DateTime.Now;
                _context.SaveChanges();
                //log it
                //record this in personstatechangelog
                var personStateLog = new Patrolpersonstatelog();
                personStateLog.Userid = u.Userid;
                personStateLog.Patrolpersonstateid = s.Patrolpersonstateid;
                personStateLog.Timestamp           = DateTime.Now;
                personStateLog.Personid            = person_mapping_exists.Personid;
                LogPersonStateChange(personStateLog);



                Operationlogs ol = new Operationlogs();
                ol.Userid      = u.Userid;
                ol.Operationid = Handler_Operations.Opeartion_Mapping_Ahwal_ChangePersonState;
                ol.Statusid    = Handler_Operations.Opeartion_Status_Success;
                ol.Text        = "احوال تغيير حالة الفرد: " + GetPerson.Milnumber + " " + 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_Ahwal_ChangePersonState;
                ol_failed.Statusid    = Handler_Operations.Opeartion_Status_UnKnownError;
                ol_failed.Text        = ex.Message;
                _oper.Add_New_Operation_Log(ol_failed);
                return(ol_failed);
            }
        }
Пример #17
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);
        }
Пример #18
0
        public Operationlogs Ops_ChangePersonState(Users u, long mappingID, Patrolpersonstates s)
        {
            try
            {
                //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(mappingID));
                if (person_mapping_exists == null)
                {
                    Operationlogs ol_failed = new Operationlogs();
                    ol_failed.Userid      = u.Userid;
                    ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_Ops_ChangePersonState;
                    ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                    ol_failed.Text        = "لم يتم العثور على التوزيع";
                    _oper.Add_New_Operation_Log(ol_failed);
                    return(ol_failed);
                }
                //a bit different here, for Ahwalmapping, allowed states are only for sick,leave,sunrise,sunset
                int[] allowedState = { Core.Handler_AhwalMapping.PatrolPersonState_Sea,
                                       Core.Handler_AhwalMapping.PatrolPersonState_Land,
                                       Core.Handler_AhwalMapping.PatrolPersonState_Back,
                                       Core.Handler_AhwalMapping.PatrolPersonState_Away,
                                       Core.Handler_AhwalMapping.PatrolPersonState_WalkingPatrol,
                                       Core.Handler_AhwalMapping.PatrolPersonState_BackFromWalking };
                //first we have to check if this user is authorized to perform this transaction
                //if (!_user.isAuthorized(u.Userid, person_mapping_exists.Ahwalid, Handler_User.User_Role_Ops)
                //    && !allowedState.Contains(s.Patrolpersonstateid))
                //{
                //    Operationlogs ol_failed = new Operationlogs();
                //    ol_failed.Userid = u.Userid;
                //    ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_Ops_ChangePersonState;
                //    ol_failed.Statusid = Handler_Operations.Opeartion_Status_UnAuthorized;
                //    ol_failed.Text = "المستخدم لايملك صلاحية هذه العمليه";
                //    _oper.Add_New_Operation_Log(ol_failed);
                //    return ol_failed;
                //}

                var GetPerson = _context.Persons.FirstOrDefault <Persons>(e => e.Personid.Equals(person_mapping_exists.Personid));
                if (GetPerson == null)
                {
                    Operationlogs ol_failed = new Operationlogs();
                    ol_failed.Userid      = u.Userid;
                    ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_Ops_ChangePersonState;
                    ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                    ol_failed.Text        = "لم يتم العثور على الفرد: " + person_mapping_exists.Personid; //todo, change it actual person name
                    _oper.Add_New_Operation_Log(ol_failed);
                    return(ol_failed);
                }
                //for operations, we cannot change person state sea land or anythinf for associate
                if (person_mapping_exists.Patrolroleid == Core.Handler_AhwalMapping.PatrolRole_Associate)
                {
                    Operationlogs ol_failed = new Operationlogs();
                    ol_failed.Userid      = u.Userid;
                    ol_failed.Operationid = Handler_Operations.Opeartion_Mapping_Ops_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); //no need to record this
                    return(ol_failed);
                }
                person_mapping_exists.Patrolpersonstateid      = s.Patrolpersonstateid;
                person_mapping_exists.Laststatechangetimestamp = DateTime.Now;
                _context.SaveChanges();
                //log it
                //record this in personstatechangelog
                var personStateLog = new Patrolpersonstatelog();
                personStateLog.Userid = u.Userid;
                personStateLog.Patrolpersonstateid = s.Patrolpersonstateid;
                personStateLog.Timestamp           = DateTime.Now;
                personStateLog.Personid            = person_mapping_exists.Personid;
                LogPersonStateChange(personStateLog);



                Operationlogs ol = new Operationlogs();
                ol.Userid      = u.Userid;
                ol.Operationid = Handler_Operations.Opeartion_Mapping_Ops_ChangePersonState;
                ol.Statusid    = Handler_Operations.Opeartion_Status_Success;
                ol.Text        = "عمليات تغيير حالة الفرد: " + GetPerson.Milnumber + " " + 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_Ahwal_ChangePersonState;
                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 Update_HandHeld(Users u, Handhelds h) //this transaction requires User_Role_Maintenance Permisson on this AhwalID
        {
            try
            {
                //first we have to check if this Users is authorized to perform this transaction
                //if (!_user.isAuthorized(u.Userid, h.Ahwalid, Handler_User.User_Role_Maintenance))
                //{
                //    Operationlogs ol_failed = new Operationlogs();
                //    ol_failed.Userid = u.Userid;
                //    ol_failed.Operationid  = Handler_Operations.Opeartion_UpdateHandHeld;
                //    ol_failed.Statusid = Handler_Operations.Opeartion_Status_UnAuthorized;
                //    ol_failed.Text = "المستخدم لايملك صلاحية هذه العمليه";
                //    _oper.Add_New_Operation_Log(ol_failed);
                //    return ol_failed;
                //}
                //next we need to search if there is a Handhelds car with same serial
                Handhelds HandHeld_exists = _context.Handhelds.FirstOrDefault(e => e.Handheldid.Equals(h.Handheldid));
                if (HandHeld_exists == null)
                {
                    Operationlogs ol_failed = new Operationlogs();
                    ol_failed.Userid      = u.Userid;
                    ol_failed.Operationid = Handler_Operations.Opeartion_UpdateHandHeld;
                    ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                    ol_failed.Text        = "لم يتم العثور على لاسلكي بالرقم: " + h.Serial;
                    _oper.Add_New_Operation_Log(ol_failed);
                    return(ol_failed);
                }
                //we have to make sure as well thats the new serial is not there before
                if (HandHeld_exists.Serial != h.Serial)//in case only the Users did choose new serial
                {
                    Handhelds same_HandHeld_serial = _context.Handhelds.FirstOrDefault(e => e.Serial.Equals(h.Serial));
                    if (same_HandHeld_serial != null)
                    {
                        Operationlogs ol_failed = new Operationlogs();
                        ol_failed.Userid      = u.Userid;
                        ol_failed.Operationid = Handler_Operations.Opeartion_UpdateHandHeld;
                        ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                        ol_failed.Text        = "يوجد لاسلكي بنفس رقم : " + h.Serial;
                        _oper.Add_New_Operation_Log(ol_failed);
                        return(ol_failed);
                    }
                }

                HandHeld_exists.Serial    = h.Serial;
                HandHeld_exists.Barcode   = "HAN" + h.Serial; //just to make sure no one miss this up even me
                HandHeld_exists.Defective = h.Defective;
                HandHeld_exists.Ahwalid   = h.Ahwalid;        //we are allowing changing of AhwalID for Patrol Cars
                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                Operationlogs ol_failed = new Operationlogs();
                ol_failed.Userid      = u.Userid;
                ol_failed.Operationid = Handler_Operations.Opeartion_UpdateHandHeld;
                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_UpdateHandHeld;
            ol.Statusid    = Handler_Operations.Opeartion_Status_Success;
            ol.Text        = "تم تعديل بيانات اللاسلكي: " + h.Handheldid;
            _oper.Add_New_Operation_Log(ol);
            return(ol);
        }