Esempio n. 1
0
        /// <summary>
        /// Saves the entity.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity">The entity.</param>
        /// <returns>
        /// id of the last inserted entity
        /// </returns>
        public long SaveEntity <T>(T entity) where T : class
        {
            _dbContext.Set <T>().Add(entity);
            _dbContext.SaveChanges();
            dynamic obj = entity;

            return(obj.id);
        }
        //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);
        }
Esempio n. 3
0
        //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);
        }
        public void PostClearIncidentCommentsView([FromBody] JObject RqHdr)
        {
            var incidentid = Convert.ToInt16(Newtonsoft.Json.JsonConvert.DeserializeObject <Int64>(RqHdr["incidentid"].ToString(), new Newtonsoft.Json.JsonSerializerSettings {
                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            }));
            var userid = Convert.ToInt16(Newtonsoft.Json.JsonConvert.DeserializeObject <Int32>(RqHdr["userid"].ToString(), new Newtonsoft.Json.JsonSerializerSettings {
                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            }));
            var incident = _context.Incidents.FirstOrDefault(em => em.Incidentid == Convert.ToInt64(incidentid));

            Users user = new Users();

            user.Userid = userid;

            //now we will clear the flag for new for this incident
            var clearIncidentView = _context.Incidentsview.FirstOrDefault <Incidentsview>(a => a.Userid == user.Userid && a.Incidentid == incident.Incidentid);

            if (clearIncidentView != null)
            {
                _context.Incidentsview.Remove(clearIncidentView);
                _context.SaveChanges();

                //IncidentsGrid.DataBind();
            }
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
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);
 }
Esempio n. 7
0
        public Operationlogs CheckOutPatrolAndHandHeld(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_CheckOutPatrolAndHandHeld;
                //    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_CheckOutPatrolAndHandHeld;
                    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_CheckOutPatrolAndHandHeld;
                    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_CheckOutPatrolAndHandHeld;
                    ol_failed.Statusid    = Handler_Operations.Opeartion_Status_Failed;
                    ol_failed.Text        = "هذا الفرد لايملك حاليا اجهزة";
                    _oper.Add_New_Operation_Log(ol_failed);
                    return(ol_failed);
                }

                //NEW Added 16/7/2017 - we have to make sure that we cannot sunset someone who currently has an incident
                if (person_mapping_exists.Incidentid != null && !person_mapping_exists.Incidentid.Equals(DBNull.Value))
                {
                    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_Failed;
                    ol_failed.Text        = "الدورية مستلمه لازالت مستلمه بلاغ-خاطب العمليات";
                    _oper.Add_New_Operation_Log(ol_failed);
                    return(ol_failed);
                }


                person_mapping_exists.Hasdevices               = Convert.ToByte(0);
                person_mapping_exists.Patrolpersonstateid      = Core.Handler_AhwalMapping.PatrolPersonState_SunSet;
                person_mapping_exists.Sunsettimestamp          = DateTime.Now;
                person_mapping_exists.Laststatechangetimestamp = DateTime.Now;



                _context.SaveChanges();
                //log it

                //we have to add this record in checkIn and CheckOut Table
                var PatrolCheckOutLog = new Patrolcheckinout();
                PatrolCheckOutLog.Checkinoutstateid = Core.Handler_AhwalMapping.CheckOutState;
                PatrolCheckOutLog.Timestamp         = DateTime.Now;
                PatrolCheckOutLog.Personid          = m.Personid;
                PatrolCheckOutLog.Patrolid          = p.Patrolid;
                // _context.Patrolcheckinout.Add(PatrolCheckOutLog);
                _context.Patrolcheckinout.Add(PatrolCheckOutLog);

                var HandHeldCheckOutLog = new Handheldscheckinout();
                HandHeldCheckOutLog.Checkinoutstateid = Core.Handler_AhwalMapping.CheckOutState;
                HandHeldCheckOutLog.Timestamp         = DateTime.Now;
                HandHeldCheckOutLog.Personid          = m.Personid;
                HandHeldCheckOutLog.Handheldid        = h.Handheldid;
                _context.Handheldscheckinout.Add(HandHeldCheckOutLog);

                _context.SaveChanges();

                //record this in personstatechangelog
                var personStateLog = new Patrolpersonstatelog();
                personStateLog.Userid = u.Userid;
                personStateLog.Patrolpersonstateid = Core.Handler_AhwalMapping.PatrolPersonState_SunSet;
                personStateLog.Timestamp           = DateTime.Now;
                personStateLog.Personid            = m.Personid;
                LogPersonStateChange(personStateLog);

                Operationlogs ol = new Operationlogs();
                ol.Userid      = u.Userid;
                ol.Operationid = Handler_Operations.Opeartion_Mapping_CheckOutPatrolAndHandHeld;
                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);
            }
        }
Esempio n. 8
0
        public Operationlogs AddUpdate_IncidentType(int incidenttypeid, string incidenttypename, 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);
                    }
                    it.Name = incidenttypename;
                    _context.SaveChanges();
                }
                else
                {
                    Incidentstypes it = new Incidentstypes();
                    //CONFIRM WITH KHALIFA
                    it.Incidenttypeid = (_context.Incidentstypes.Count() + 1);
                    it.Name           = incidenttypename;
                    _context.Incidentstypes.Add(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);
        }