public void CrearEmpresa(Empresa empresa) { try { string BASE_URL2 = "http://ws.razonsocialperu.com/rest/PROYUPC/RUC/"; string urlConsulta = string.Format("{0}/{1}", BASE_URL2, empresa.NumeroRuc); var webClient = new WebClient(); var json = webClient.DownloadString(urlConsulta); var js = new JavaScriptSerializer(); var result = js.DeserializeObject(json); Dictionary<string, object> lista = ((object[])(result))[0] as Dictionary<string, object>; var estado = lista.Where(x => x.Key == "status") as Dictionary<string, object>; string value = lista["status"].ToString(); if (value != "EXISTS") throw new WebFaultException<string>("El RUC ingresado no se encuentra registrado en los sistemas tributarios.", HttpStatusCode.NotFound); EmpresaDAO.Crear(empresa); WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Created; } catch (Exception ex) { throw ex; } }
public Empresa CrearEmpresa(string email, string clave, string razonSocial, string numeroRuc, int idRubro) { Rubro rubroExistente = RubroDAO.Obtener(idRubro); Empresa usuarioCrear = new Empresa() { EmailContacto = email, Clave = clave, RazonSocial = razonSocial, NumeroRuc = numeroRuc, Rubro = rubroExistente }; return EmpresaDAO.Crear(usuarioCrear); }
public void CrearEmpresa() { try { string BASE_URL2 = "http://ws.razonsocialperu.com/rest/PROYUPC/RUC/"; string urlConsulta = string.Format("{0}/{1}", BASE_URL2, "10428225240"); var webClient = new WebClient(); var json = webClient.DownloadString(urlConsulta); var js = new JavaScriptSerializer(); var result = js.DeserializeObject(json); Dictionary<string, object> lista = ((object[])(result))[0] as Dictionary<string, object>; var estado = lista.Where(x => x.Key == "status") as Dictionary<string, object>; string value = lista["status"].ToString(); string error = string.Empty; if (value != "EXISTS") error = "El RUC ingresado no se encuentra registrado en los sistemas tributarios."; string url = string.Format("{0}/Empresas", BASE_URL); Rubro rubro = new Rubro() { Id = 22, Descripcion = "Tecnología y sistemas" }; Empresa empresa = new Empresa() { Id = 193, EmailContacto = "*****@*****.**", Clave = "D12345678", NumeroRuc = "11111111111", RazonSocial = "Sistemas", Rubro = rubro }; var serial = new DataContractJsonSerializer(typeof(Empresa)); var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/json"; using (var requestStream = request.GetRequestStream()) { serial.WriteObject(requestStream, empresa); } var response = (HttpWebResponse)request.GetResponse(); var status = response.StatusCode; Assert.AreEqual(HttpStatusCode.Created, status); } catch (WebException ex) { var json = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd(); var js = new JavaScriptSerializer(); var data = js.Deserialize<string>(json); Assert.AreEqual("Empresa no encontrada.", data); } }
public void ModificarEmpresa() { try { string url = string.Format("{0}/Empresas", BASE_URL); Rubro rubro = new Rubro() { Id = 22, Descripcion = "Tecnología y sistemas" }; Empresa empresa = new Empresa() { Id = 301, EmailContacto = "*****@*****.**", Clave = "123456", NumeroRuc = "12345658909", RazonSocial = "Otra prueba", Rubro = rubro }; var serial = new DataContractJsonSerializer(typeof(Empresa)); var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "PUT"; request.ContentType = "application/json"; using (var requestStream = request.GetRequestStream()) { serial.WriteObject(requestStream, empresa); } var response = (HttpWebResponse)request.GetResponse(); var status = response.StatusCode; Assert.AreEqual(HttpStatusCode.OK, status); } catch (WebException ex) { var json = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd(); var js = new JavaScriptSerializer(); var data = js.Deserialize<string>(json); Assert.AreEqual("Empresa no encontrada.", data); } }
public void ModificarEmpresa(Empresa empresa) { int idEmpresa = empresa.Id; var empresaEncontrada = EmpresaDAO.Obtener(idEmpresa); if (empresaEncontrada != null) { empresaDAO.Modificar(empresa); } else throw new WebFaultException<string>("Empresa no encontrada.", HttpStatusCode.NotFound); }
public Empresa ModificarEmpresa(int id, string email, string clave, string razonSocial, string numeroRuc, int idRubro) { Rubro rubroExistente = RubroDAO.Obtener(idRubro); Empresa empresaModificar = new Empresa() { Id = id, EmailContacto = email, Clave = clave, RazonSocial = razonSocial, NumeroRuc = numeroRuc, Rubro = rubroExistente }; return EmpresaDAO.Modificar(empresaModificar); }
public OperationStatus CrearEmpresa(string email, string clave, string razonSocial, string numeroRuc, int idRubro) { try { Rubro rubroExistente = RubroDAO.Obtener(idRubro); Empresa empresaCrear = new Empresa() { EmailContacto = email, Clave = clave, RazonSocial = razonSocial, NumeroRuc = numeroRuc, Rubro = rubroExistente }; var validationContext = new ValidationContext(empresaCrear, serviceProvider: null, items: null); var validationResults = new List<ValidationResult>(); var isValid = Validator.TryValidateObject(empresaCrear, validationContext, validationResults, true); if (!isValid) { OperationStatus opStatus = new OperationStatus(); opStatus.Success = false; foreach (ValidationResult message in validationResults) { opStatus.Messages.Add(message.ErrorMessage); } return opStatus; } else { EmpresaDAO.Crear(empresaCrear); return new OperationStatus { Success = true }; } } catch (Exception e) { return OperationStatus.CreateFromException("Al crear la empresa.", e); } }