Пример #1
0
        public ActionResult OnGet(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            try
            {
                client.Headers["Content-type"] = "application/json";
                Stream       data   = client.OpenRead(Program.Baseurl + "/LPT/Grandeza/" + id);
                StreamReader reader = new StreamReader(data);
                string       s      = reader.ReadToEnd();
                MemoryStream ms     = new MemoryStream(Encoding.Unicode.GetBytes(s));
                grandeza = ser.ReadObject(ms) as Grandeza;
                data.Close();
                reader.Close();
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
                grandeza = new Grandeza();
            }

            if (grandeza.IdGrandeza == 0)
            {
                return(NotFound());
            }

            Page_Title = id + " - Alterar Grandeza ";
            return(Page());
        }
Пример #2
0
 public IActionResult Update(int IdGrandeza, [FromBody] Grandeza newObject)
 {
     try {
         var c = repositorio.Update(IdGrandeza, newObject);
         return(this.Ok(c));
     }
     catch (Exception ex) {
         Console.WriteLine(ex.Message);
         return(BadRequest());
     }
 }
Пример #3
0
 public IActionResult Create([FromBody] Grandeza t)
 {
     try {
         var c = repositorio.Create(t);
         Console.WriteLine("ok ");
         return(this.Ok(c));
     }
     catch (Exception) {
         Console.WriteLine("erro");
         return(BadRequest());
     }
 }
Пример #4
0
 public object Read(int IdGrandeza)
 {
     try
     {
         Grandeza r = (from p in context.Grandeza where p.IdGrandeza == IdGrandeza select p).FirstOrDefault <Grandeza>();
         return(r);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(null);
     }
 }
Пример #5
0
 public object Create(object p)
 {
     try
     {
         Grandeza r = (context.Grandeza.Add((Grandeza)p)).Entity;
         context.SaveChanges();
         return(r);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(null);
     }
 }
Пример #6
0
 public object Update(int IdGrandeza, object newObject)
 {
     try
     {
         Grandeza r = (from p in context.Grandeza where p.IdGrandeza == IdGrandeza select p).FirstOrDefault <Grandeza>();
         foreach (var att in ((Grandeza)newObject).GetType().GetProperties())
         {
             if (!att.Name.Equals("IdGrandeza"))
             {
                 r.GetType().GetProperty(att.Name).SetValue(r, att.GetValue(newObject));
             }
         }
         context.Entry(r).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
         context.SaveChanges();
         return(r);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(null);
     }
 }
Пример #7
0
 public ActionResult OnGet()
 {
     grandeza   = new Grandeza();
     Page_Title = " - novo Grandeza ";
     return(Page());
 }