public PartialViewResult AddedMessages() { user user = (user)Session[ECGlobalConstants.CurrentUserMarcker]; // if (user == null || user.id == 0 || user.role_id == 4 || user.role_id == 5 || user.role_id == 6 || user.role_id == 7) // return RedirectToAction("Index", "Account"); int sender_id = Convert.ToInt16(Request["sender_id"]); if (user.id != sender_id) { // security issue sender_id = user.id; } int report_id = Convert.ToInt16(Request["report_id"]); // check if sender has access to report int reporter_access = Convert.ToInt16(Request["reporter_access"]); string body_tx = (string)(Request["body_tx"]); message _message = new message(); _message.created_dt = DateTime.Now; _message.ip_ds = ""; _message.subject_ds = ""; _message.body_tx = body_tx; _message.report_id = report_id; _message.reporter_access = reporter_access; _message.sender_id = sender_id; db.message.Add(_message); try { db.SaveChanges(); glb.UpdateReportLog(_message.sender_id, 7, _message.report_id, "", null, ""); // send emails to Case Admin #region Email to Case Admin ReportModel rm = new ReportModel(_message.report_id); foreach (user _user in rm.MediatorsWhoHasAccessToReport()) { if ((_user.email.Trim().Length > 0) && m_EmailHelper.IsValidEmail(_user.email.Trim())) { List <string> to = new List <string>(); List <string> cc = new List <string>(); List <string> bcc = new List <string>(); to.Add(_user.email.Trim()); /// bcc.Add("*****@*****.**"); EC.Business.Actions.Email.EmailManagement em = new EC.Business.Actions.Email.EmailManagement(); EC.Business.Actions.Email.EmailBody eb = new EC.Business.Actions.Email.EmailBody(1, 1, Request.Url.AbsoluteUri.ToLower()); eb.NewMessage(_user.first_nm, _user.last_nm, rm._report.display_name); string body = eb.Body; /////// em.Send(to, cc, App_LocalResources.GlobalRes.Email_Title_NewMessage, body, true); } } #endregion } catch (Exception ex) { logger.Error(ex.ToString()); ///// return or log error?? } CaseMessagesViewModel cmvm = new CaseMessagesViewModel().BindMessageToViewMessage(_message, sender_id); PartialViewResult pvr = PartialView("~/Views/Shared/Helpers/_SingleMessage.cshtml", cmvm); return(pvr); }
public string Email(string email) { if (email != null && email.Length > 0) { if (m_EmailHelper.IsValidEmail(email.Trim())) { ECEntities db = new ECEntities(); if (db.user.Any(t => (t.email.ToLower().Trim() == email.ToLower().Trim()) && (t.role_id != 8))) { user _user = (db.user.Where(t => t.email.ToLower().Trim() == email.ToLower().Trim())).First(); if (_user != null) { string password_token = Convert.ToBase64String(Guid.NewGuid().ToByteArray()); user_change_password _ucp = new user_change_password(); _ucp.password_token = password_token; _ucp.user_id = _user.id; _ucp.user_ip = ""; _ucp.password_updated = 0; _ucp.created_on = DateTime.Today; db.user_change_password.Add(_ucp); try { db.SaveChanges(); #region Email Sending List <string> to = new List <string>(); List <string> cc = new List <string>(); List <string> bcc = new List <string>(); to.Add(email.Trim()); /// bcc.Add("*****@*****.**"); EC.Business.Actions.Email.EmailManagement em = new EC.Business.Actions.Email.EmailManagement(); EC.Business.Actions.Email.EmailBody eb = new EC.Business.Actions.Email.EmailBody(1, 1, Request.Url.AbsoluteUri.ToLower()); eb.ForgetPasswordNew(Request.Url.AbsoluteUri.ToLower(), email, password_token); string body = eb.Body; em.Send(to, cc, App_LocalResources.GlobalRes.ChangePasswordRequest, body, true); #endregion } catch (Exception ex) { logger.Error(ex.ToString()); return(ex.ToString()); } return(GlobalRes.Success.ToLower()); } } return(GlobalRes.NoUserFound); } else { return(GlobalRes.EmailInvalid); } } else { return(GlobalRes.EnterYourEmail); } }
public string InviteMediator(string email) { email = email.ToLower().Trim(); user _user = (user)Session[ECGlobalConstants.CurrentUserMarcker]; if (_user == null || _user.id == 0) { return(App_LocalResources.GlobalRes.EmptyData); } if (_user.role_id == 8) { return(App_LocalResources.GlobalRes.EmptyData); } if (string.IsNullOrEmpty(email)) { return(App_LocalResources.GlobalRes.EmptyData); } if (!m_EmailHelper.IsValidEmail(email)) { return(App_LocalResources.GlobalRes.EmailInvalid); } UserModel um = new UserModel(_user.id); List <string> _company_user_emails = new List <string>(); _company_user_emails = (db.user.Where(t => ((t.company_id == um._user.company_id) && (t.role_id != ECLevelConstants.level_informant))).Select(t => t.email.Trim().ToLower())).ToList(); List <int> _company_user_allowed = new List <int>(); _company_user_allowed = (db.user.Where(t => ((t.company_id == um._user.company_id) && (t.role_id != ECLevelConstants.level_informant))).Select(t => t.id)).ToList(); if (_company_user_emails.Contains(email)) { return(App_LocalResources.GlobalRes.MediatorAlreadyRegistered + "!"); } if ((db.invitation.Any(t => ((t.email.ToLower().Trim() == email) && (t.used_flag == 1) && (_company_user_allowed.Contains(t.sent_by_user_id))))) || (db.user.Any(u => ((u.email.ToLower().Trim() == email.ToLower().Trim() && u.role_id != 8))))) { return(App_LocalResources.GlobalRes.MediatorAlreadyRegistered); } if (db.invitation.Any(t => ((t.email.ToLower().Trim() == email) && (_company_user_allowed.Contains(t.sent_by_user_id))))) { return(App_LocalResources.GlobalRes.AlreadyInvited); } string generated_code = StringUtil.RandomString(6); // create invitation in db invitation _invitation = new invitation(); _invitation.code = generated_code; _invitation.comment = ""; _invitation.created_on = DateTime.Now; _invitation.email = email.Trim().ToLower(); _invitation.sent_by_user_id = _user.id; _invitation.used_flag = 0; db.invitation.AddOrUpdate(_invitation); db.SaveChanges(); // add _invitation to db // send email with code to email address if ((email.Trim().Length > 0) && m_EmailHelper.IsValidEmail(email.Trim())) { List <string> to = new List <string>(); List <string> cc = new List <string>(); List <string> bcc = new List <string>(); to.Add(email.Trim()); /// bcc.Add("*****@*****.**"); EC.Business.Actions.Email.EmailManagement em = new EC.Business.Actions.Email.EmailManagement(); EC.Business.Actions.Email.EmailBody eb = new EC.Business.Actions.Email.EmailBody(1, 1, Request.Url.AbsoluteUri.ToLower()); CompanyModel cm = new CompanyModel(_user.company_id); eb.MediatorInvited(_user.first_nm, _user.last_nm, _user.first_nm, _user.last_nm, cm._company.company_nm, generated_code, DomainUtil.GetSubdomainLink(Request.Url.AbsoluteUri.ToLower()) + "/new/?code=" + generated_code + "&email=" + email); string body = eb.Body; em.Send(to, cc, App_LocalResources.GlobalRes.Email_Title_MediatorInvited, body, true); } return(App_LocalResources.GlobalRes._Completed.ToLower()); }
public ActionResult UpdateMediator([Bind(Include = "id,status_id,role_id")] user _user) { user session_user = (user)Session[ECGlobalConstants.CurrentUserMarcker]; if (session_user == null || session_user.id == 0) { return(RedirectToAction("Index", "Account")); } if (ModelState.IsValid) { using (var db1 = new ECEntities()) { user _updateuser = db1.user.Where(item => item.id == _user.id).FirstOrDefault(); _updateuser.status_id = _user.status_id; _updateuser.role_id = _user.role_id; bool _status_change = false; if ((_user.status_id == 2) && (_updateuser.status_id != 2)) { _status_change = true; } bool _role_change = false; if (_user.role_id != _updateuser.role_id) { _role_change = true; } List <string> to = new List <string>(); List <string> cc = new List <string>(); List <string> bcc = new List <string>(); CompanyModel cm = new CompanyModel(_user.company_id); EC.Business.Actions.Email.EmailManagement em = new EC.Business.Actions.Email.EmailManagement(); EC.Business.Actions.Email.EmailBody eb = new EC.Business.Actions.Email.EmailBody(1, 1, Request.Url.AbsoluteUri.ToLower()); string body = ""; if (_role_change) { if ((_updateuser.email.Trim().Length > 0) && m_EmailHelper.IsValidEmail(_updateuser.email.Trim())) { to = new List <string>(); cc = new List <string>(); bcc = new List <string>(); to.Add(_updateuser.email.Trim()); /// bcc.Add("*****@*****.**"); string new_role = ""; user_role new_roledb = db.user_role.Where(t => t.id == _user.role_id).FirstOrDefault(); if (new_roledb != null) { new_role = new_roledb.role_en; } eb.MediatorRoleChange(_updateuser.first_nm, _updateuser.last_nm, session_user.first_nm, session_user.last_nm, new_role); body = eb.Body; em.Send(to, cc, App_LocalResources.GlobalRes.Email_Title_MediatorRoleChanged, body, true); } } if (_status_change) { if ((_updateuser.email.Trim().Length > 0) && m_EmailHelper.IsValidEmail(_updateuser.email.Trim())) { to = new List <string>(); cc = new List <string>(); bcc = new List <string>(); to.Add(_updateuser.email.Trim()); /// bcc.Add("*****@*****.**"); string new_status = ""; status new_roledb = db.status.Where(t => t.id == _user.status_id).FirstOrDefault(); if (new_status != null) { new_status = new_roledb.status_en; } eb.MediatorStatusChange(_updateuser.first_nm, _updateuser.last_nm, session_user.first_nm, session_user.last_nm, new_status); body = eb.Body; em.Send(to, cc, App_LocalResources.GlobalRes.Email_Title_MediatorStatusChanged, body, true); } } db1.SaveChanges(); return(RedirectToAction("User", new { id = _user.id })); } } return(RedirectToAction("User", new { id = _user.id })); }
public object Post(Filter filter) { user user = (user)HttpContext.Current.Session[ECGlobalConstants.CurrentUserMarcker]; if (user == null || user.id == 0) { return(null); } if (filter.AddToTeam.HasValue) { UserModel userModel = UserModel.inst; GlobalFunctions glb = new GlobalFunctions(); IEmailAddressHelper m_EmailHelper = new EmailAddressHelper(); userModel.AddToMediators(filter.AddToTeam.Value, filter.Report_id.Value); UserModel _um = new UserModel(filter.AddToTeam.Value); glb.UpdateReportLog(user.id, 5, filter.Report_id.Value, _um._user.first_nm + " " + _um._user.last_nm, null, ""); if ((_um._user.email.Trim().Length > 0) && m_EmailHelper.IsValidEmail(_um._user.email.Trim())) { List <string> to = new List <string>(); List <string> cc = new List <string>(); List <string> bcc = new List <string>(); to.Add(_um._user.email.Trim()); ReportModel _rm = new ReportModel(filter.Report_id.Value); EC.Business.Actions.Email.EmailManagement em = new EC.Business.Actions.Email.EmailManagement(); EC.Business.Actions.Email.EmailBody eb = new EC.Business.Actions.Email.EmailBody(1, 1, HttpContext.Current.Request.Url.AbsoluteUri.ToLower()); eb.MediatorAssigned(_um._user.first_nm, _um._user.last_nm, user.first_nm, user.last_nm, _rm._report.display_name); string body = eb.Body; em.Send(to, cc, LocalizationGetter.GetString("Email_Title_MediatorAssigned", false), body, true); } } if (filter.RemoveFromTeam.HasValue) { UserModel _um = new UserModel(filter.RemoveFromTeam.Value); int tasks_number = _um.UserTasks(1, filter.Report_id.Value, true).Count(); if (tasks_number == 0) { UserModel userModel = UserModel.inst; GlobalFunctions glb = new GlobalFunctions(); userModel.RemoveMediator(filter.RemoveFromTeam.Value, filter.Report_id.Value); glb.UpdateReportLog(user.id, 6, filter.Report_id.Value, _um._user.first_nm + " " + _um._user.last_nm, null, ""); } else { return(Get(filter.Report_id.Value, false, "User have a tasks")); } } if (filter.MakeCaseOwner.HasValue) { var list = DB.report_owner.Where(x => x.report_id == filter.Report_id).ToList(); foreach (var item in list) { item.status_id = item.user_id == filter.MakeCaseOwner.Value ? 2 : 1; } if (list.FirstOrDefault(x => x.user_id == filter.MakeCaseOwner.Value) == null) { DB.report_owner.Add(new report_owner { created_on = DateTime.Now, report_id = filter.Report_id.Value, user_id = filter.MakeCaseOwner.Value, status_id = 2, }); } DB.SaveChanges(); } return(Get(filter.Report_id.Value)); }
public object Post(user model) { user curUser = (user)HttpContext.Current.Session[ECGlobalConstants.CurrentUserMarcker]; var user = DB.user.FirstOrDefault(x => x.id == model.id); //Change only own settings //Can not add if ((curUser.role_id != 5) & (user == null || curUser.id != user.id)) { return(new { result = 0, ok = true, }); } if (user != null) { user.first_nm = model.first_nm; user.last_nm = model.last_nm; user.title_ds = model.title_ds; user.email = model.email; user.role_id = model.role_id; user.company_department_id = model.company_department_id; user.company_location_id = model.company_location_id; user.user_permissions_approve_case_closure = model.user_permissions_approve_case_closure; user.user_permissions_change_settings = model.user_permissions_change_settings; user.status_id = model.status_id; } else { var glb = new GlobalFunctions(); if (DB.user.Any(x => x.email.ToLower() == model.email.ToLower() && x.company_id == curUser.company_id)) { return(new { ok = false, message = $"User with email '{model.email}' already exists!", }); } int language_id = 1; int location_id = model.company_location_id ?? 0; if (model.company_location_id == 0) { List <company_location> company_locations = DB.company_location.Where(t => t.company_id == curUser.company_id && t.status_id == 2).OrderBy(t => t.id).ToList(); if (company_locations.Count > 0) { location_id = company_locations[0].id; } } user = new user(); user.first_nm = model.first_nm.Trim(); user.last_nm = model.last_nm.Trim(); user.company_id = curUser.company_id; if (curUser.role_id == 5) { user.role_id = model.role_id; user.status_id = model.status_id; user.user_permissions_approve_case_closure = model.user_permissions_approve_case_closure; user.user_permissions_change_settings = model.user_permissions_change_settings; } else { //Activate if pendind user.status_id = user.status_id == 3 ? 2 : user.status_id; } user.login_nm = glb.GenerateLoginName(user.first_nm, user.last_nm); user.password = glb.GeneretedPassword().Trim(); user.photo_path = ""; user.email = model.email.Trim(); user.phone = ""; user.preferred_contact_method_id = 1; user.title_ds = model.title_ds.Trim(); user.employee_no = ""; user.company_department_id = model.company_department_id; user.question_ds = ""; user.answer_ds = ""; user.previous_login_dt = DateTime.Now; user.previous_login_dt = null; user.last_update_dt = DateTime.Now; user.user_id = 1; user.preferred_email_language_id = language_id; user.notification_messages_actions_flag = 1; user.notification_new_reports_flag = 1; user.notification_marketing_flag = 1; user.notification_summary_period = 1; user.company_location_id = location_id; user.location_nm = ""; user.sign_in_code = null; user.guid = Guid.NewGuid(); DB.user.Add(user); var company = DB.company.FirstOrDefault(x => x.id == curUser.company_id); EC.Business.Actions.Email.EmailManagement em = new EC.Business.Actions.Email.EmailManagement(); EC.Business.Actions.Email.EmailBody eb = new EC.Business.Actions.Email.EmailBody(1, 1, HttpContext.Current.Request.Url.AbsoluteUri.ToLower()); eb.NewMediator( $"{curUser.first_nm} {curUser.last_nm}", $"{company.company_nm}", HttpContext.Current.Request.Url.AbsoluteUri.ToLower(), HttpContext.Current.Request.Url.AbsoluteUri.ToLower(), $"{user.login_nm}", $"{user.password}"); string body = eb.Body; em.Send(model.email.ToLower(), "You have been added as a Case Administrator", body, true); } DB.SaveChanges(); return(new { result = 0, ok = true, }); }
public bool AcceptOrReopenCase() { int report_id = Convert.ToInt16(Request["report_id"]); int user_id = Convert.ToInt16(Request["user_id"]); string description = "";// Request["description"]; int scopeId = Convert.ToInt32(Request["scopeId"]); int severityId = Convert.ToInt32(Request["severityId"]); //int departmentId = Convert.ToInt32(Request["departmentId"]); //int incidentId = Convert.ToInt32(Request["incidentId"]); int ownerId = Convert.ToInt32(Request["ownerId"]); bool lifeThreat = Convert.ToBoolean(Request["isLifeThreat"]); using (ECEntities adv = new ECEntities()) { report_investigation_status addStatus = new report_investigation_status() { report_id = report_id, investigation_status_id = 3, created_date = DateTime.Now, user_id = user_id, description = description }; adv.report_investigation_status.Add(addStatus); var item = db.report_mediator_assigned.FirstOrDefault(x => x.report_id == report_id & x.mediator_id == ownerId); if (item == null) { //Remove owner foreach (var rem_owner in db.report_owner.Where(x => x.report_id == report_id).ToList()) { rem_owner.status_id = 1; } //New owner var owner = new report_owner { report_id = report_id, status_id = 2, user_id = ownerId, created_on = DateTime.Now, }; db.report_owner.Add(owner); db.SaveChanges(); //Add to mediators var report_mediator_assigned = new report_mediator_assigned { mediator_id = ownerId, case_owner_id = owner.id, assigned_dt = DateTime.Now, last_update_dt = DateTime.Now, report_id = report_id, status_id = 2, user_id = user_id, }; db.report_mediator_assigned.Add(report_mediator_assigned); db.SaveChanges(); } adv.SaveChanges(); } using (ECEntities adv = new ECEntities()) { user user = (user)Session[ECGlobalConstants.CurrentUserMarcker]; var report = adv.report.FirstOrDefault(x => x.id == report_id); report.scope_id = scopeId; report.severity_id = severityId; report.severity_user_id = user.id; report.scope_user_id = user.id; report.cc_is_life_threating = lifeThreat; report.cc_is_life_threating_created_date = DateTime.Now; report.cc_is_life_threating_user_id = user.id; adv.SaveChanges(); } // Case accepted glb.UpdateReportLog(user_id, 17, report_id, description, null, ""); glb.UpdateReportLog(user_id, 20, report_id, App_LocalResources.GlobalRes._Completed, null, ""); glb.UpdateReportLog(user_id, 21, report_id, App_LocalResources.GlobalRes._Started, null, ""); report_log _log = new report_log(); ReportModel rm = new ReportModel(report_id); CompanyModel cm = new CompanyModel(rm._report.company_id); UserModel um = new UserModel(user_id); #region Email Ready List <string> to = new List <string>(); List <string> cc = new List <string>(); List <string> bcc = new List <string>(); EC.Business.Actions.Email.EmailManagement em = new EC.Business.Actions.Email.EmailManagement(); EC.Business.Actions.Email.EmailBody eb = new EC.Business.Actions.Email.EmailBody(1, 1, Request.Url.AbsoluteUri.ToLower()); string body = ""; #endregion if (EC.Common.Util.DomainUtil.IsCC(Request)) { if (lifeThreat) { glb.UpdateReportLog(user_id, 16, report_id, "", null, ""); glb.CampusSecurityAlertEmail(rm._report, Request.Url, db, cm._company.cc_campus_alert_manager_email); glb.CampusSecurityAlertEmail(rm._report, Request.Url, db, cm._company.cc_daily_crime_log_manager_email); } } if (!db.report_log.Any(item => ((item.action_id == 19) && (item.report_id == report_id)))) { //case opened glb.UpdateReportLog(user_id, 19, report_id, description, null, ""); #region Email To Mediators About Case Approved foreach (user _user in rm.MediatorsWhoHasAccessToReport()) { if ((_user.email.Trim().Length > 0) && m_EmailHelper.IsValidEmail(_user.email.Trim())) { to = new List <string>(); cc = new List <string>(); bcc = new List <string>(); to.Add(_user.email.Trim()); eb.NextStep(_user.first_nm, _user.last_nm, rm._report.display_name); body = eb.Body; /// em.Send(to, cc, App_LocalResources.GlobalRes.Email_Title_NextStep, body, true); } } #endregion #region Email to Reporter About case been Approved if ((rm._reporter_user.email.Trim().Length > 0) && m_EmailHelper.IsValidEmail(rm._reporter_user.email.Trim())) { to = new List <string>(); cc = new List <string>(); bcc = new List <string>(); to.Add(rm._reporter_user.email.Trim()); eb.NextStep(um._user.first_nm, um._user.last_nm, rm._report.display_name); body = eb.Body; em.Send(to, cc, App_LocalResources.GlobalRes.Email_Title_NextStep, body, true); } #endregion } else { // case re-opened glb.UpdateReportLog(user_id, 29, report_id, description, null, ""); #region Email To Mediators About Case re-opening foreach (user _user in rm.MediatorsWhoHasAccessToReport()) { if ((_user.email.Trim().Length > 0) && m_EmailHelper.IsValidEmail(_user.email.Trim())) { to = new List <string>(); cc = new List <string>(); bcc = new List <string>(); to.Add(_user.email.Trim()); /// bcc.Add("*****@*****.**"); eb.CaseReopened(_user.first_nm, _user.last_nm, rm._report.display_name, um._user.first_nm, um._user.last_nm); body = eb.Body; em.Send(to, cc, App_LocalResources.GlobalRes.Email_Title_CaseReopened, body, true); } } #endregion #region Email to Reporter About case been reopened if ((rm._reporter_user.email.Trim().Length > 0) && m_EmailHelper.IsValidEmail(rm._reporter_user.email.Trim())) { to = new List <string>(); cc = new List <string>(); bcc = new List <string>(); to.Add(rm._reporter_user.email.Trim()); /// bcc.Add("*****@*****.**"); eb.ReporterCaseReopened(rm._report.display_name); body = eb.Body; em.Send(to, cc, App_LocalResources.GlobalRes.Email_Title_CaseReopened, body, true); } #endregion } ///// glb.UpdateReportLog(user_id, 20, report_id, App_LocalResources.GlobalRes._Completed, null, description); ////// glb.UpdateReportLog(user_id, 21, report_id, App_LocalResources.GlobalRes._Started, null, ""); return(true); }