public Task <IHttpActionResult> GetEmployeeForToken() { IHttpActionResult result = NotFound(); try { SOFTTEK.SCMS.Foundation.Business.BusinessContext ctx = new SOFTTEK.SCMS.Foundation.Business.BusinessContext { SecurityContext = new Foundation.Security.SecurityContext { DeviceID = GetDeviceIdentifier(), ClientID = GetToken().Identifier, AuthorizationTicket = GetToken().Identifier, AppID = new System.Configuration.AppSettingsReader().GetValue("S_SRA_APP_idENTIFIER", typeof(string)).ToString() } }; SOFTTEK.SCMS.Business.SRA.EmployeeBO employeeBO = new Business.SRA.EmployeeBO(ctx); SOFTTEK.SCMS.Entity.Shared.Employee employee = employeeBO.GetEmployeeInfoForToken(); employee.ImageURL = string.Empty; if (employee != null) { result = Json(employee); } } catch (Exception ex) { result = Error(ex); } return(Task.FromResult(result)); }
public Task <HttpResponseMessage> GetEmployeeImageForToken() { HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.NotFound); try { SOFTTEK.SCMS.Foundation.Business.BusinessContext ctx = new SOFTTEK.SCMS.Foundation.Business.BusinessContext { SecurityContext = new Foundation.Security.SecurityContext { DeviceID = GetDeviceIdentifier(), ClientID = GetToken().Identifier, AuthorizationTicket = GetToken().Identifier, AppID = new System.Configuration.AppSettingsReader().GetValue("S_SRA_APP_idENTIFIER", typeof(string)).ToString() } }; SOFTTEK.SCMS.Business.SRA.EmployeeBO employeeBO = new Business.SRA.EmployeeBO(ctx); SOFTTEK.SCMS.Entity.Shared.Employee employee = employeeBO.GetEmployeeInfoForToken(); if (employee == null) { return(Task.FromResult(result)); } Uri ftpAddress = null; if (!Uri.TryCreate(employee.ImageURL, UriKind.Absolute, out ftpAddress)) { result = new HttpResponseMessage(HttpStatusCode.Conflict); return(Task.FromResult(result)); } if (ftpAddress.Scheme != Uri.UriSchemeFtp) { result = new HttpResponseMessage(HttpStatusCode.Conflict); return(Task.FromResult(result)); } WebClient request = new WebClient(); byte[] imageData = request.DownloadData(ftpAddress); var ms = new System.IO.MemoryStream(imageData); var t = new StringContent(Convert.ToBase64String(imageData), System.Text.UTF8Encoding.UTF8, "image/jpg"); result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = t; } catch (Exception ex) { result = new HttpResponseMessage(HttpStatusCode.Conflict); result.Content = new StringContent(ex.Message); } return(Task.FromResult(result)); }
public SOFTTEK.SCMS.Entity.Shared.Employee GetEmployeeInfoForToken() { SOFTTEK.SCMS.Entity.Shared.Employee employee = null; return(context.Execute(() => { using (dataSource = new SRADataContext(context.SecurityContext)) { dataSource.ConnectionString = "SRA"; dataSource.DefaultUser = new System.Configuration.AppSettingsReader().GetValue("S_APP_UID", typeof(string)).ToString(); dataSource.Initialize(); employee = dataSource.GetEmployeeWithToken(); } return employee; }, "Retrieve the employee information for the user related to the provided token.")); }
/// <summary> /// Approve a non approved registede activity. /// </summary> /// <param name="activityID">Activity Identifier</param> /// <returns></returns> public T ApproveActivity <T>(long activityID, SOFTTEK.SCMS.Entity.Shared.Employee approver, string comments) where T : SOFTTEK.SCMS.Entity.SRA.Activity, new() { T changedActivity = context.Execute(() => { T targetActivity = new T(); using (dataSource = new SRADataContext(context.SecurityContext)) { dataSource.ConnectionString = "SRA"; dataSource.DefaultUser = System.Configuration.ConfigurationManager.AppSettings["S_APP_UID"]; dataSource.Initialize(); var result = dataSource.GetActivityByID(activityID); targetActivity = new T { ActivityCode = result.ActivityCode, ApprovedAt = result.ApprovedAt, ApprovedBy = result.ApprovedBy, ApprovedComments = result.ApprovedComments, Details = result.Details, Effort = result.Effort, Employee = result.Employee, ExecutedAt = result.ExecutedAt, Identifier = result.Identifier, Jornade = result.Jornade, Project = result.Project, ReportedAt = result.ReportedAt, State = result.State }; } return(targetActivity); }, "Retrieve information for an activity to be updated"); ValidateModifiableActivityState(changedActivity); ValidateApproval(changedActivity, approver); changedActivity.State = APPROVED_ACTIVITY_STATE; changedActivity.ApprovedAt = DateTime.Now; changedActivity.ApprovedComments = comments; changedActivity = UpdateActivity <T>(changedActivity); return(changedActivity); }
public Task <IHttpActionResult> PutActivityApproval(string id, [FromBody] string comments) { int activityID; IHttpActionResult result = NotFound(); if (!int.TryParse(id, out activityID)) { result = Conflict(); return(Task.FromResult(result)); } try { SOFTTEK.SCMS.Foundation.Business.BusinessContext ctx = new SOFTTEK.SCMS.Foundation.Business.BusinessContext { SecurityContext = new Foundation.Security.SecurityContext { DeviceID = GetDeviceIdentifier(), ClientID = GetToken().Identifier, AuthorizationTicket = GetToken().Identifier, AppID = new System.Configuration.AppSettingsReader().GetValue("S_SRA_APP_idENTIFIER", typeof(string)).ToString() } }; SOFTTEK.SCMS.Business.SRA.EmployeeBO employeeBO = new Business.SRA.EmployeeBO(ctx); SOFTTEK.SCMS.Business.SRA.ActivityBO activitiesRegisterBO = new Business.SRA.ActivityBO(ctx); SOFTTEK.SCMS.Entity.Shared.Employee approver = employeeBO.GetEmployeeInfoForToken(); SOFTTEK.SCMS.Entity.SRA.Activity updatedActivity = activitiesRegisterBO.ApproveActivity <SOFTTEK.SCMS.Business.Entity.SRA.ARSDetailedActivity>(activityID, approver, comments); List <SOFTTEK.SCMS.Business.Entity.SRA.ARSDetailedActivity> activitiesToApprove = activitiesRegisterBO.GetActivitiesToApprove <SOFTTEK.SCMS.Business.Entity.SRA.ARSDetailedActivity>(approver.Identifier, updatedActivity.Project); if (activitiesToApprove.Count > 0) { result = Json(activitiesToApprove); } } catch (Exception ex) { result = Error(ex); } return(Task.FromResult(result)); }
private void ValidateApproval(SOFTTEK.SCMS.Entity.SRA.Activity targetActivity, SCMS.Entity.Shared.Employee approver) { bool isValidApproverForActivity = context.Execute(() => { EmployeeBO employeeBO = new EmployeeBO(context); SOFTTEK.SCMS.Entity.Shared.Employee employee = employeeBO.GetEmployeeInfoById(targetActivity.Employee.Identifier); if (employee.Supervisor.Identifier == approver.Identifier) { return(true); } return(false); }, "Validate approver with activity's employee supervisor"); if (!isValidApproverForActivity) { throw new Exception("El aprovador no corresponde al supervisor de quien reporta la actividad a aprovar", new InvalidOperationException("Inconsistencia entre el supervisor del empleado asociado a la actividad, y el aprovador proporcionado para la solicitud.")); } }
public async Task <HttpResponseMessage> Get(string id) { int employeeID = 0; if (int.TryParse(id, out employeeID)) { SOFTTEK.SCMS.Foundation.Business.BusinessContext ctx = new SOFTTEK.SCMS.Foundation.Business.BusinessContext { SecurityContext = new Foundation.Security.SecurityContext { DeviceID = GetDeviceIdentifier(), ClientID = GetToken().Identifier, AuthorizationTicket = GetToken().Identifier, AppID = new System.Configuration.AppSettingsReader().GetValue("S_SRA_APP_idENTIFIER", typeof(string)).ToString() } }; SOFTTEK.SCMS.Business.SRA.EmployeeBO employeeBO = new Business.SRA.EmployeeBO(ctx); SOFTTEK.SCMS.Entity.Shared.Employee employee = employeeBO.GetEmployeeInfoById(employeeID); if (employee != null) { Uri ftpAddress = null; if (Uri.TryCreate(employee.ImageURL, UriKind.Absolute, out ftpAddress)) { if (ftpAddress.Scheme != Uri.UriSchemeFtp) { return(new HttpResponseMessage(HttpStatusCode.Conflict)); } return(await SOFTTEK.SCMS.Foundation.Web.Ftp.GetContent(ftpAddress)); } return(new HttpResponseMessage(HttpStatusCode.Conflict)); } return(new HttpResponseMessage(HttpStatusCode.NotFound)); } return(new HttpResponseMessage(HttpStatusCode.Conflict)); }
public bool SetEmployeeImage(string ftpURL, int employeeID) { bool result = false; return(context.Execute(() => { using (dataSource = new SRADataContext(context.SecurityContext)) { dataSource.ConnectionString = "SRA"; dataSource.DefaultUser = new System.Configuration.AppSettingsReader().GetValue("S_APP_UID", typeof(string)).ToString(); dataSource.Initialize(); SOFTTEK.SCMS.Entity.Shared.Employee employee = dataSource.GetEmployeeById(employeeID); if (employee != null) { employee.ImageURL = ftpURL; result = dataSource.UpdateEmployee(employee); } ; return result; } }, "Upload to the images repository, the provided binary image file.")); }