//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 static OperationLog Login_User(User u) //{ // DataClassesDataContext db = new DataClassesDataContext(Handler_Global.connectString); // User user_exists = db.Users.FirstOrDefault(e => e.UserName.Equals(u.UserName.ToLower())); // if (user_exists == null) // { // OperationLog ol_failed = new OperationLog(); // ol_failed.UserID = 1; //we should log this by admin // ol_failed.OperationID = Handler_Operations.Opeartion_UserLogin; // ol_failed.StatusID = Handler_Operations.Opeartion_Status_LoginFail; // ol_failed.Text = "لايوجد مستخدم بالاسم: " + u.UserName; // Handler_Operations.Add_New_Operation_Log(ol_failed); // return ol_failed; // } // //check if account is locked // if (user_exists.AccountLocked==1) // { // OperationLog ol_failed = new OperationLog(); // ol_failed.UserID = 1; //we should log this by admin // ol_failed.OperationID = Handler_Operations.Opeartion_UserLogin; // ol_failed.StatusID = Handler_Operations.Opeartion_Status_LoginFail; // ol_failed.Text = "تم قفل الحساب: " + u.UserName; // //Handler_Operations.Add_New_Operation_Log(ol_failed);// I dont think we need to store this log // return ol_failed; // } // //check password // var correctHashedPassword = user_exists.Password; // var submittedValue = user_exists.Password; // // var submittedValue = Core.Handler_User.GenerateHash(u.Password + user_exists.Salt).ToUpper() ; // if (correctHashedPassword != submittedValue) // { // //we have to log this attempt // user_exists.LastFailedLogin = DateTime.Now; // user_exists.FailedLogins++; // user_exists.LastIPAddress = u.LastIPAddress; // if (user_exists.FailedLogins > 3) //lock the account with three failed logins // { // user_exists.AccountLocked = 1; // } // db.SubmitChanges(); // OperationLog ol_failed = new OperationLog(); // ol_failed.UserID = 1; //we should log this by admin // ol_failed.OperationID = Handler_Operations.Opeartion_UserLogin; // ol_failed.StatusID = Handler_Operations.Opeartion_Status_LoginFail; // ol_failed.Text = "خطا في كلمة المرور للمستخدم: " + u.UserName; // Handler_Operations.Add_New_Operation_Log(ol_failed); // return ol_failed; // } // user_exists.LastSuccessLogin = DateTime.Now; // user_exists.FailedLogins=0; //reset failed logins // user_exists.LastIPAddress = u.LastIPAddress; // db.SubmitChanges(); // OperationLog ol = new OperationLog(); // ol.UserID = 1; //we should log this by admin // ol.OperationID = Handler_Operations.Opeartion_UserLogin; // ol.StatusID = Handler_Operations.Opeartion_Status_Success; // ol.Text = "تسجيل دخول: " + u.UserName; // Handler_Operations.Add_New_Operation_Log(ol); // return ol; //} public bool isAuthorized(long userid, long ahwalid, long userRoleID) { Usersrolesmap permisson_esists = _context.Usersrolesmap.FirstOrDefault(r => r.Userid == userid && r.Ahwalid == ahwalid && r.Userroleid == userRoleID); if (permisson_esists == null) { return(false); } return(true); }
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); }
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 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); }