public Rubro CrearRubro(string descripcion)
 {
     Rubro usuarioCrear = new Rubro()
     {
         Descripcion  = descripcion
     };
     return RubroDAO.Crear(usuarioCrear);
 }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
0
 public void CrearRubro(Rubro rubro)
 {
     RubroDAO.Crear(rubro);
     WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Created;
 }
Beispiel #5
0
 public void ModificarRubro(Rubro rubro)
 {
     int idRubro = rubro.Id;
     var rubroEncontrada = RubroDAO.Obtener(idRubro);
     if (rubroEncontrada != null)
     {
         rubroDAO.Modificar(rubro);
     }
     else
         throw new WebFaultException<string>("Rubro no encontrado.", HttpStatusCode.NotFound);
 }
 public Rubro ModificarRubro(int id, string descripcion)
 {
     Rubro usuarioModificar = new Rubro()
     {
         Id = id,
         Descripcion = descripcion
     };
     return RubroDAO.Modificar(usuarioModificar);
 }
 public Rubro CrearRubro(string descripcion)
 {
     Rubro empresaCrear = new Rubro()
     {
         Descripcion  = descripcion
     };
     return RubroDAO.Crear(empresaCrear);
 }