public ActionResult PostAddIncidentComments([FromBody] JObject RqHdr)
        {
            var userid = Convert.ToInt32(Newtonsoft.Json.JsonConvert.DeserializeObject <Int32>(RqHdr["userid"].ToString(), new Newtonsoft.Json.JsonSerializerSettings {
                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            }));
            var incidentid = Convert.ToInt64(Newtonsoft.Json.JsonConvert.DeserializeObject <Int64>(RqHdr["incidentid"].ToString(), new Newtonsoft.Json.JsonSerializerSettings {
                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            }));
            // var commenttext = Convert.ToString(Newtonsoft.Json.JsonConvert.DeserializeObject<string>(RqHdr["commenttext"].ToString(), new Newtonsoft.Json.JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore }));
            var commenttext = RqHdr["commenttext"].ToString();


            //var user = (User)sessionuser;
            Users user = new Users();

            user.Userid = userid;
            var newComment = new Incidentscomments();

            newComment.Incidentid = Convert.ToInt64(incidentid.ToString());
            newComment.Text       = commenttext;
            newComment.Userid     = userid;
            var result = _inc.Add_New_Comment(user, newComment);

            return(Ok(result));
        }
        //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);
        }
Esempio n. 3
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);
        }
        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);
        }
Esempio n. 5
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);
        }