public UserContext Initialize(string SSOID, string pwd, bool activeOnly) { SQM.Website.PSsqmEntities ctx = new PSsqmEntities(); this.LoginStatus = LoginStatus.SSOUndefined; SQM_ACCESS access = SQMModelMgr.LookupCredentials(ctx, SSOID, pwd, true); if (access != null) { string key = SQMModelMgr.GetPasswordKey(); // AW - for now, we want to allow if the password = the password OR the encrypted password string password = WebSiteCommon.Decrypt(access.PASSWORD, key); //string encrypt = WebSiteCommon.Encrypt(pwd, key); //string ss = encrypt; /* * if ((string.IsNullOrEmpty(pwd) && (SSOID.ToLower() != "admin")) || (pwd != password && pwd != access.PASSWORD)) * this.LoginStatus = LoginStatus.PasswordMismatch; */ //if (!string.IsNullOrEmpty(access.PASSWORD) && (pwd != password && pwd != access.PASSWORD)) if (pwd != password && pwd != access.PASSWORD) { this.LoginStatus = LoginStatus.PasswordMismatch; } else if (activeOnly && access.STATUS == "I") { this.LoginStatus = LoginStatus.Inactive; } else if (access.STATUS == "L") { this.LoginStatus = LoginStatus.Locked; } else { if ((this.Person = SQMModelMgr.LookupPerson(ctx, 0, access.SSO_ID, false)) == null) { this.LoginStatus = LoginStatus.PersonUndefined; } else { this.LoginStatus = LoginStatus.Success; this.HRLocation = new BusinessLocation().Initialize(SQMModelMgr.LookupCompany((decimal)this.Person.COMPANY_ID), SQMModelMgr.LookupBusOrg((decimal)this.Person.BUS_ORG_ID), SQMModelMgr.LookupPlant((decimal)this.Person.PLANT_ID)); if (this.HRLocation.Company == null) { this.LoginStatus = LoginStatus.CompanyUndefined; } else { this.PrivList = SQMModelMgr.SelectPrivGroupPerson(this.Person.PRIV_GROUP, "COMMON"); SessionManager.EffLocation = new BusinessLocation().Initialize(SQMModelMgr.LookupCompany((decimal)this.Person.COMPANY_ID), SQMModelMgr.LookupBusOrg((decimal)this.Person.BUS_ORG_ID), SQMModelMgr.LookupPlant((decimal)this.Person.PLANT_ID)); this.WorkingLocation = new BusinessLocation(); this.WorkingLocation = SessionManager.EffLocation; this.PlantAccessList = new List <decimal>(); this.PlantAccessList.Add(this.WorkingLocation.Plant.PLANT_ID); if (!string.IsNullOrEmpty(Person.NEW_LOCATION_CD)) { decimal plantID; string[] locs = Person.NEW_LOCATION_CD.Split(','); foreach (string locid in locs) { if (!string.IsNullOrEmpty(locid)) { if (decimal.TryParse(locid, out plantID) && plantID != this.WorkingLocation.Plant.PLANT_ID) { this.PlantAccessList.Add(plantID); } } } } access.LAST_LOGON_DT = WebSiteCommon.CurrentUTCTime(); int ctxstatus = 0; SQMModelMgr.UpdateCredentials(ctx, access, "", out ctxstatus); this.Credentials = access; this.TimeZoneID = this.HRLocation.Plant.LOCAL_TIMEZONE; this.LocalTime = !string.IsNullOrEmpty(this.TimeZoneID) ? WebSiteCommon.LocalTime(DateTime.UtcNow, this.TimeZoneID) : DateTime.UtcNow; this.Language = SQMModelMgr.LookupLanguage(ctx, "", this.Person.PREFERRED_LANG_ID.HasValue ? (int)this.Person.PREFERRED_LANG_ID : 1, false); if (SessionManager.CreateSessionContext(this) == null) { this.LoginStatus = LoginStatus.SessionError; } this.InboxReviews = 0; } } } } return(this); }
public UserContext Initialize(string SSOID, string pwd, bool activeOnly) { SQM.Website.PSsqmEntities ctx = new PSsqmEntities(); this.LoginStatus = LoginStatus.SSOUndefined; SQM_ACCESS access = SQMModelMgr.LookupCredentials(ctx, SSOID, pwd, true); if (access != null) { string key = SQMModelMgr.GetPasswordKey(); // AW - for now, we want to allow if the password = the password OR the encrypted password string password = WebSiteCommon.Decrypt(access.PASSWORD, key); //string encrypt = WebSiteCommon.Encrypt(pwd, key); //string ss = encrypt; /* * if ((string.IsNullOrEmpty(pwd) && (SSOID.ToLower() != "admin")) || (pwd != password && pwd != access.PASSWORD)) * this.LoginStatus = LoginStatus.PasswordMismatch; */ //if (!string.IsNullOrEmpty(access.PASSWORD) && (pwd != password && pwd != access.PASSWORD)) if (pwd != password && pwd != access.PASSWORD) { this.LoginStatus = LoginStatus.PasswordMismatch; } else if (activeOnly && access.STATUS == "I") { this.LoginStatus = LoginStatus.Inactive; } else if (access.STATUS == "L") { this.LoginStatus = LoginStatus.Locked; } else { if ((this.Person = SQMModelMgr.LookupPerson(ctx, 0, access.SSO_ID, false)) == null) { this.LoginStatus = LoginStatus.PersonUndefined; } else { this.LoginStatus = LoginStatus.Success; this.HRLocation = new BusinessLocation().Initialize(SQMModelMgr.LookupCompany((decimal)this.Person.COMPANY_ID), SQMModelMgr.LookupBusOrg((decimal)this.Person.BUS_ORG_ID), SQMModelMgr.LookupPlant((decimal)this.Person.PLANT_ID)); if (this.HRLocation.Company == null) { this.LoginStatus = LoginStatus.CompanyUndefined; } else { SessionManager.EffLocation = new BusinessLocation().Initialize(SQMModelMgr.LookupCompany((decimal)this.Person.COMPANY_ID), SQMModelMgr.LookupBusOrg((decimal)this.Person.BUS_ORG_ID), SQMModelMgr.LookupPlant((decimal)this.Person.PLANT_ID)); if (this.Person.PERSON_RESP.ALT_COMPANY_ID > 0) { this.WorkingLocation = new BusinessLocation().Initialize(SQMModelMgr.LookupCompany((decimal)this.Person.PERSON_RESP.ALT_COMPANY_ID), SQMModelMgr.LookupBusOrg((decimal)this.Person.PERSON_RESP.ALT_BUS_ORG_ID), SQMModelMgr.LookupPlant((decimal)this.Person.PERSON_RESP.ALT_PLANT_ID)); } else { this.WorkingLocation = new BusinessLocation(); this.WorkingLocation = SessionManager.EffLocation; } //this.WorkingLocation = new BusinessLocation().Initialize(SQMModelMgr.LookupCompany((decimal)this.Person.COMPANY_ID), SQMModelMgr.LookupBusOrg((decimal)this.Person.BUS_ORG_ID), SQMModelMgr.LookupPlant((decimal)this.Person.PLANT_ID)); this.PlantAccessList = new List <decimal>(); if (!string.IsNullOrEmpty(Person.NEW_LOCATION_CD)) { decimal plantID; string[] locs = Person.NEW_LOCATION_CD.Split(','); foreach (string locid in locs) { if (decimal.TryParse(locid, out plantID)) { this.PlantAccessList.Add(plantID); } } } access.LAST_LOGON_DT = WebSiteCommon.CurrentUTCTime(); int ctxstatus = 0; SQMModelMgr.UpdateCredentials(ctx, access, "", out ctxstatus); this.Credentials = access; this.TimeZoneID = WebSiteCommon.GetXlatValue("timeZone", this.Person.PREFERRED_TIMEZONE); this.DelegateList = new List <decimal>(); this.DelegateList = SQMModelMgr.SelectDelegateList(ctx, this.Person.PERSON_ID).Select(l => l.PERSON_ID).ToList(); this.EscalationAssignments = SQMModelMgr.SelectPersonEscalationList(ctx, this.Person.PERSON_ID); if (SessionManager.CreateSessionContext(this) == null) { this.LoginStatus = LoginStatus.SessionError; } this.InboxReviews = 0; this.TaskList = new List <TaskItem>(); } } } } return(this); }
public static ATTACHMENT AddAttachment(String filename, String description, decimal?display_type, string docScope, int recordType, decimal recordID, string recordStep, string sessionID, Stream file, int Incident_Section) { ATTACHMENT ret = null; try { using (PSsqmEntities entities = new PSsqmEntities()) { ATTACHMENT d = new ATTACHMENT(); d.FILE_NAME = filename; d.FILE_DESC = description; //To-do: what do we do when company_id is not set, like when they choose this // from the Business Org master screen? d.COMPANY_ID = SessionManager.EffLocation.Company.COMPANY_ID; d.OWNER_ID = SessionManager.UserContext.Person.PERSON_ID; d.UPLOADED_BY = SessionManager.UserContext.Person.FIRST_NAME + " " + SessionManager.UserContext.Person.LAST_NAME; d.UPLOADED_DT = WebSiteCommon.CurrentUTCTime(); d.LANGUAGE_ID = (int)SessionManager.UserContext.Person.PREFERRED_LANG_ID; d.ATTACHMENT_SCOPE = docScope; d.RECORD_TYPE = recordType; d.RECORD_ID = recordID; // we might not have the record id when the attaachment is created d.RECORD_STEP = recordStep; d.SESSION_ID = sessionID; d.INCIDENT_SECTION = Incident_Section; if (display_type.HasValue) { d.DISPLAY_TYPE = display_type.Value; } if (d.ATTACHMENT_FILE == null) { d.ATTACHMENT_FILE = new ATTACHMENT_FILE(); } //read in the file contents file.Seek(0, SeekOrigin.Begin); byte[] bytearray = new byte[file.Length]; int count = 0; while (count < file.Length) { bytearray[count++] = Convert.ToByte(file.ReadByte()); } d.ATTACHMENT_FILE.ATTACHMENT_DATA = bytearray; d.FILE_SIZE = file.Length; // d.DISPLAY_TYPE = Path.GetExtension(filename); entities.AddToATTACHMENT(d); entities.SaveChanges(); ret = d; } } catch (Exception e) { //SQMLogger.LogException(e); ret = null; } return(ret); }
public static VIDEO_ATTACHMENT UpdateVideoAttachment(decimal videoAttachId, String filename, String description, String title, decimal?display_type, int recordType, decimal recordID, string sessionID, Stream file) { VIDEO_ATTACHMENT ret = null; try { using (PSsqmEntities entities = new PSsqmEntities()) { ret = (from d in entities.VIDEO_ATTACHMENT.Include("VIDEO_ATTACHMENT_FILE") where ( (d.VIDEO_ATTACH_ID == videoAttachId) ) select d).Single(); ret.RECORD_TYPE = recordType; ret.VIDEO_ID = recordID; // we might not have the record id when the attaachment is created ret.FILE_NAME = filename; ret.DESCRIPTION = description; ret.ATTACHMENT_TYPE_ID = recordType.ToString(); //To-do: what do we do when company_id is not set, like when they choose this // from the Business Org master screen? ret.UPLOADED_ID = SessionManager.UserContext.Person.PERSON_ID; ret.UPLOADED_DT = WebSiteCommon.CurrentUTCTime(); ret.TITLE = title; //d.ATTACHMENT_SCOPE = docScope; ret.SESSION_ID = sessionID; if (display_type.HasValue) { ret.DISPLAY_TYPE = display_type.Value; } if (ret.VIDEO_ATTACHMENT_FILE == null) { ret.VIDEO_ATTACHMENT_FILE = new VIDEO_ATTACHMENT_FILE(); } //read in the file contents if (file != null) { file.Seek(0, SeekOrigin.Begin); byte[] bytearray = new byte[file.Length]; int count = 0; while (count < file.Length) { bytearray[count++] = Convert.ToByte(file.ReadByte()); } ret.VIDEO_ATTACHMENT_FILE.VIDEO_ATTACH_DATA = bytearray; ret.FILE_SIZE = file.Length; } // d.DISPLAY_TYPE = Path.GetExtension(filename); entities.SaveChanges(); } } catch (Exception e) { //SQMLogger.LogException(e); ret = null; } return(ret); }
public static VIDEO Add(String fileName, String fileExtention, String description, string videoTitle, int sourceType, decimal sourceId, string sourceStep, string injuryType, string bodyPart, string videoType, DateTime videoDate, DateTime incidentDate, Stream file, decimal plantId) { VIDEO ret = null; try { using (PSsqmEntities entities = new PSsqmEntities()) { VIDEO video = new VIDEO(); //video.FILE_NAME = filename; video.DESCRIPTION = description; video.TITLE = videoTitle; video.SOURCE_TYPE = sourceType; video.SOURCE_ID = sourceId; video.SOURCE_STEP = sourceStep; if (plantId > 0) { PLANT plant = SQMModelMgr.LookupPlant(plantId); video.COMPANY_ID = (decimal)plant.COMPANY_ID; video.BUS_ORG_ID = (decimal)plant.BUS_ORG_ID; video.PLANT_ID = plantId; } else { video.COMPANY_ID = SessionManager.EffLocation.Company.COMPANY_ID; video.BUS_ORG_ID = SessionManager.UserContext.Person.BUS_ORG_ID; video.PLANT_ID = SessionManager.UserContext.Person.PLANT_ID; } video.VIDEO_PERSON = SessionManager.UserContext.Person.PERSON_ID; video.CREATE_DT = WebSiteCommon.CurrentUTCTime(); video.VIDEO_TYPE = videoType; // this is the injury/incident type. Default to 0 for Media & audit video.VIDEO_DT = videoDate; video.INCIDENT_DT = incidentDate; video.INJURY_TYPES = injuryType; video.BODY_PARTS = bodyPart; video.VIDEO_STATUS = ""; //video.FILE_NAME = fileName; video.FILE_SIZE = file.Length; entities.AddToVIDEO(video); entities.SaveChanges(); // use the video id, but have to save video video.FILE_NAME = video.VIDEO_ID.ToString() + fileExtention; entities.SaveChanges(); // this is the code for saving the file in the Azure cloud if (video != null) { // get the container from the settings table List <SETTINGS> sets = SQMSettings.SelectSettingsGroup("MEDIA_UPLOAD", ""); string storageContainer = sets.Find(x => x.SETTING_CD == "STORAGE_CONTAINER").VALUE.ToString(); CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(storageContainer); CloudBlockBlob blockBlob = container.GetBlockBlobReference(video.VIDEO_ID.ToString() + fileExtention); blockBlob.UploadFromStream(file); } ret = video; } } catch (Exception e) { //SQMLogger.LogException(e); ret = null; } return(ret); }