public ProductProjectModule(IProductProjectService productProjectService) : base("/productproject") { this._productProjectService = productProjectService; this.Post( "/", parameters => { try { var productProject = this.Bind <ProductProject>(); var serviceReturn = new ServiceReturn <ProductProject>(); //serviceReturn.Data = this._productProjectService.Save(productProject); serviceReturn.Success = true; return(this.GetJsonResponse(serviceReturn)); } catch (Exception e) { return(this.Negotiate.WithStatusCode(HttpStatusCode.InternalServerError)); } }); }
public ActionResult Aprovar(int id) { ServiceReturn check = null; Solicitacao solicitacao = SolicitacaoService.Obter(id); solicitacao.DataAutorizacao = DateTime.Now; solicitacao.Atualizacao = DateTime.Now; solicitacao.Atualizador = User.Identity.Name; try { //SolicitacaoService.AprovarSolicitacao(solicitacao); check = new ServiceReturn() { success = true, title = "Sucesso", message = "Solicitação de aprovada com sucesso!", id = solicitacao.IdSolicitacao }; } catch (Exception ex) { check = new ServiceReturn() { success = false, title = "Erro", message = string.Format("Erro ao aprovar a solicitação! {0} - {1}", ex.GetType(), ex.Message), id = 0 }; } return(Json(check, JsonRequestBehavior.AllowGet)); }
public MyResult Delete(string par0, int par1) { ServiceReturn ret = new ServiceReturn(); Assembly asmb = Assembly.GetAssembly(typeof(ServiceReturn)); Type type = asmb.GetType(par0); DBBase.Delete(type, par1); return(ServiceResult(par1.ToString())); }
public ProjectModule(IProjectService projectService) : base("projects") { this._projectService = projectService; this.Get( "/{salesexecid}", parameters => { try { var salesExecId = parameters.salesexecid; var projects = this._projectService.GetProjectsWithProductsForOneExec(salesExecId); return(this.GetJsonResponse(projects)); } catch (System.Exception e) { return(this.Negotiate.WithStatusCode(Nancy.HttpStatusCode.InternalServerError)); } }); this.Get( "/leadership", parameters => { try { var projects = this._projectService.GetAllExecProjectsWithProducts(); return(this.GetJsonResponse(projects)); } catch (Exception e) { return(this.Negotiate.WithStatusCode(Nancy.HttpStatusCode.InternalServerError)); } }); this.Post( "/", parameters => { try { var project = this.Bind <Project>(); var serviceReturn = new ServiceReturn <Project>(); serviceReturn.Data = this._projectService.Save(project); serviceReturn.Success = true; return(this.GetJsonResponse(serviceReturn)); } catch (Exception e) { return(this.Negotiate.WithStatusCode(HttpStatusCode.InternalServerError)); } }); }
public MyResult Change(string par0, string par1) { ServiceReturn ret = new ServiceReturn(); Assembly asmb = Assembly.GetAssembly(typeof(ServiceReturn)); Type type = asmb.GetType(par0); object obj = JsonConvert.DeserializeObject(par1, type); object newObj = DBBase.Change(obj); return(ServiceResult(newObj)); }
public MyResult Get(string par0, int par1) { ServiceReturn ret = new ServiceReturn(); Assembly asmb = Assembly.GetAssembly(typeof(ServiceReturn)); Type type = asmb.GetType(par0); object newObj = null; if (type == typeof(EProject)) { newObj = DBBase.Get <EProject>(par1); } else if (type == typeof(EFeedback)) { newObj = DBBase.Get <EFeedback>(par1); } else if (type == typeof(EMessage)) { newObj = DBBase.Get <EMessage>(par1); } else if (type == typeof(EPeople)) { newObj = DBBase.Get <EPeople>(par1); } else if (type == typeof(EPlan)) { newObj = DBBase.Get <EPlan>(par1); } else if (type == typeof(EProjectTeam)) { newObj = DBBase.Get <EProjectTeam>(par1); } else if (type == typeof(ETask)) { newObj = DBBase.Get <ETask>(par1); } else if (type == typeof(ETaskTransfer)) { newObj = DBBase.Get <ETaskTransfer>(par1); } else if (type == typeof(EUser)) { newObj = DBBase.Get <EUser>(par1); } else if (type == typeof(EUserSearch)) { newObj = DBBase.Get <EUserSearch>(par1); } return(ServiceResult(newObj)); }
private ServiceReturn GetFolderDocumentsByPath(string folderPath, int start, int count, string sortColumn) { // Remove trailing / so only folder name is passed if (folderPath.LastIndexOf('/') == folderPath.Length - 1) { folderPath = folderPath.Remove(folderPath.LastIndexOf('/')); } ServiceReturn result = new ServiceReturn(); ExceptionsML bizEx = null; if (count == 0) { count = 1000; } var folderClient = SvcBldr.FolderV2(); // If the folder is the root, get all children if (folderPath == Constants.i18n("folders")) { // if the root, pass in an empty path (null works too) folderPath = string.Empty; } else { // If the folder is below the root remove the root from the path string[] foldBelowRoot = folderPath.Split('/'); var len = foldBelowRoot.Length; folderPath = string.Join("/", foldBelowRoot, 1, len - 1); } var sr = folderClient.SearchByPath(new SearchByPathPackage { EntityPath = folderPath, Count = count, SortColumn = sortColumn, Start = start }); if (sr.Error != null) { result.BizEx = bizEx; return(result); } if (sr.Result == null) { result.BizEx = new ExceptionsML() { Message = Constants.i18n("folderDoesNotExist") }; return(result); } result.Result = sr.Result; return(result); }
public ActionResult CreateATIV([Bind(Include = "IdSolicitacao,Criacao,Criador,Atualizacao,Atualizador,Ativo,TipoEmissao,VeiculoId,AeroportoId,EmpresaId,ContratoId,TipoSolicitacaoId,Area1Id,Area2Id,PortaoAcesso1Id,PortaoAcesso2Id,PortaoAcesso3Id")] Solicitacao solicitacao, FormCollection form) { solicitacao.Criador = solicitacao.Atualizador = User.Identity.Name; #region //solicitacao.Veiculo = new Veiculo() { IdVeiculo = (int.Parse(form["VeiculoId"])) }; //solicitacao.Empresa = new Empresa() { IdEmpresa = (int.Parse(form["EmpresaId"])) }; //solicitacao.Contrato = new Contrato() { IdContrato = int.Parse(form["ContratoId"]) }; //solicitacao.TipoSolicitacao = new TipoSolicitacao() { IdTipoSolicitacao = int.Parse(form["TipoSolicitacaoId"]) }; //solicitacao.Area1 = new Entity.Entities.Area() { IdArea = int.Parse(form["Area1Id"]) }; //solicitacao.Area2 = !string.IsNullOrEmpty(form["Area2Id"]) ? new Entity.Entities.Area() { IdArea = int.Parse(form["Area2Id"]) } : null; //solicitacao.PortaoAcesso = new PortaoAcesso() { IdPortaoAcesso = int.Parse(form["PortaoAcessoId"]) }; #endregion ServiceReturn check = SolicitacaoService.SalvarATIV(solicitacao); #region //try //{ // SolicitacaoService.SalvarATIV(solicitacao); // check = new ServiceReturn() // { // success = true, // title = "Sucesso", // message = "Solicitação de ATIV cadastrada com sucesso!", // id = solicitacao.IdSolicitacao // }; //} //catch (Exception ex) //{ // check = new ServiceReturn() // { // success = false, // title = "Erro", // message = string.Format("Erro ao cadastrar a solicitação de ATIV! {0} - {1}", ex.GetType(), ex.Message), // id = 0 // }; //} #endregion return(Json(check, JsonRequestBehavior.AllowGet)); }
/// <summary> /// GetSpecialtyByID -> Sincrono /// Usado para ir buscar a especialidade no caso do utilizador selecionar primeiro o ato médico /// </summary> /// <param name="task"></param> /// <returns>Returna uma especialidade</returns> public static ServiceReturn <Specialty> RunSync(Func <Task <ServiceReturn <Specialty> > > task) { #region uimessage var uiMessages = new Dictionary <string, string>(); if (!string.IsNullOrEmpty("")) { uiMessages.Add(ServiceReturnHandling.GenericMessageKey, ""); } else { uiMessages.Add(ServiceReturnHandling.GenericMessageKey, "Erro ao obter a especialidade"); } if (!string.IsNullOrEmpty("")) { uiMessages.Add(ServiceReturnHandling.SuccessMessageKey, ""); } #endregion var oldContext = SynchronizationContext.Current; var synch = new ExclusiveSynchronizationContext(); SynchronizationContext.SetSynchronizationContext(synch); ServiceReturn <Specialty> ret = default(ServiceReturn <Specialty>); synch.Post(async _ => { try { ret = await task(); } catch (Exception e) { synch.InnerException = e; throw; } finally { synch.EndMessageLoop(); } }, null); synch.BeginMessageLoop(); SynchronizationContext.SetSynchronizationContext(oldContext); return(ret);//ServiceReturnHandling.BuildSuccessCallReturn<Specialty>(ret, uiMessages); }
private ServiceReturn GetInboxDocuments(string inboxId, int start, int count, string sortColumn) { if (count == 0) { count = 1000; } var sr = new SearchRequest { Start = start, MaxRows = count, InboxId = new Guid(inboxId), IncludeDocuments = true, SortBy = sortColumn }; var client = SvcBldr.SearchV2(); var sr1 = client.Search(sr); var result = new ServiceReturn(); result.Result = sr1.Result; result.BizEx = sr1.Error; return(result); }
public MyResult() { ServiceReturn = new ServiceReturn(); }
/// <summary> /// Execute the service /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void runToolStripMenuItem1_Click(object sender, EventArgs e) { try { // Re-register the client every time, incase it's kicked connection.Register(); var ip = queriedService.Ip; var port = queriedService.Port; try { queriedService = connection.QueryService(serviceTag).Service; } catch (Exception) { throw new Exception("Service is no longer registered"); } var serviceConnection = new ServiceConnection(Program.Logger, teamName, ip, port, false, connection.TeamId); var call = new RemoteServiceCall(queriedService.Name, teamName, (int)connection.TeamId); int i = 1; foreach (DataGridViewRow row in argGrid.Rows) { var argName = row.Cells[0].Value.ToString(); var argDataType = ServiceArgument.TypeFromString(row.Cells[1].Value.ToString()); var argMandatory = row.Cells[2].Value.ToString().Equals("true", StringComparison.CurrentCultureIgnoreCase); var argValue = row.Cells[3].Value.ToString(); // Are we mandatory or do we have a value? if (argMandatory || !String.IsNullOrWhiteSpace(argValue)) { if (String.IsNullOrWhiteSpace(argValue)) { throw new FormatException("Please enter a value for: " + argName); } try { switch (argDataType) { case ServiceDataType.Tint: int.Parse(argValue); break; case ServiceDataType.Tdouble: double.Parse(argValue); break; case ServiceDataType.Tfloat: float.Parse(argValue); break; case ServiceDataType.Tchar: if (argValue.Length > 1) { throw new FormatException("Char field must be 1 character"); } break; case ServiceDataType.Tshort: short.Parse(argValue); break; case ServiceDataType.Tlong: long.Parse(argValue); break; default: break; } } catch (Exception) { throw new FormatException("Please enter a proper value for: " + argName); } } var arg = new ServiceArgument(i++, argName, argDataType, argMandatory); arg.Value = argValue; call.Args.Add(arg); } i = 1; foreach (DataGridViewRow row in respGrid.Rows) { var respName = row.Cells[0].Value.ToString(); var respDataType = ServiceArgument.TypeFromString(row.Cells[1].Value.ToString()); var respValue = ""; var ret = new ServiceReturn(i++, respName, respDataType, respValue); call.Returns.Add(ret); } var executeResponse = serviceConnection.ExecuteService(call); foreach (var ret in executeResponse.Returned.Returns) { foreach (DataGridViewRow row in respGrid.Rows) { var respName = row.Cells[0].Value.ToString(); if (respName == ret.Name) { var respDataType = ServiceArgument.TypeFromString(row.Cells[1].Value.ToString()); row.Cells[2].Value = ret.Value; break; } } } } catch (Exception ex) { MessageBox.Show("Error executing service, because: " + ex.Message); } }
public ProductModule(IProductService productService, IProductProjectService productProjectService) : base("lookup") { this._productService = productService; this._productProjectService = productProjectService; this.Get( "/products", parameters => { try { var products = this._productService.Get().ToList(); return(this.GetJsonResponse(products)); } catch (Exception e) { return(this.Negotiate.WithStatusCode(HttpStatusCode.InternalServerError)); } }); this.Get( "/products/{projectid}", parameters => { try { var projectId = parameters.projectid; var products = this._productService.GetAllForProject(projectId); return(this.GetJsonResponse(products)); } catch (Exception e) { return(this.Negotiate.WithStatusCode(HttpStatusCode.InternalServerError)); } }); this.Post( "/projects/{projectid}/products", parameters => { try { var projectId = parameters.projectid; var products = this.Bind <List <Product> >(); var serviceReturn = new ServiceReturn <List <ProductProject> >(); serviceReturn.Data = this._productProjectService.Save(products, projectId); serviceReturn.Success = true; return(this.GetJsonResponse(serviceReturn)); } catch (Exception e) { Console.WriteLine(e); throw; } }); }
IEnumerator WebApiEx <T>(string action, Action <ServiceReturn> backAction, params object[] pars) { string url = ServiceManager.ServiceUrl + action; WWWForm form = new WWWForm(); for (int i = 0; i < pars.Length; i++) { if (pars[i] == null) { form.AddField("par" + i, "null"); continue; } Type type = pars[i].GetType(); if (!type.IsClass || type == typeof(string) || type == typeof(DateTime) || type.BaseType == typeof(System.Type) || type.IsEnum || type == typeof(int) || type == typeof(float) ) { form.AddField("par" + i, pars[i].ToString()); } else { form.AddField("par" + i, JsonConvert.SerializeObject(pars[i])); } } if (form.data.Length == 0) { form.AddField("par0", "none"); } Dictionary <string, string> header = form.headers; header.Add("SessionKey", Session.GetSessionKey()); WWW www = new WWW(url, form.data, header); yield return(www); CallWebApiStartFrameCount = 0; if (www.error != null) { App.Instance.HintBox.Show(www.error); } else { ServiceReturn ret = JsonConvert.DeserializeObject <ServiceReturn>(www.text); if (!ret.IsSucceed) { App.Instance.HintBox.Show(ret.Message); } else { Type type = typeof(T); if (type == typeof(string) || type == typeof(DateTime) || type.BaseType == typeof(System.Type) || type == typeof(int) || type == typeof(float) ) { ret.SetData(ret.GetData().ToString()); } else if (type.IsEnum) { ret.SetData(Enum.Parse(typeof(T), ret.GetData().ToString())); } else { if (ret.GetData() == null) { ret.SetData(null); } else { T data = JsonConvert.DeserializeObject <T>(ret.GetData().ToString()); ret.SetData(data); } } backAction(ret); } } App.Instance.DataLoading.Hide(); }