public bool savePerson([FromBody] PersonCLS oPersonCLS) { bool response = false; try { using (BDRestauranteContext bd = new BDRestauranteContext()) { if (oPersonCLS.IdPerson == 0) { Persona oPerson = new Persona { Apmaterno = oPersonCLS.apMaterno, Appaterno = oPersonCLS.apPaterno, Iidpersona = oPersonCLS.IdPerson, Nombre = oPersonCLS.Name, Correo = oPersonCLS.Email, Telefono = oPersonCLS.PhoneNumber, Fechanacimiento = oPersonCLS.Birthday, Bhabilitado = 1, Btieneusuario = 0 }; bd.Add(oPerson); } else { Persona oPerson = bd.Persona.Where(p => p.Iidpersona == oPersonCLS.IdPerson).FirstOrDefault(); oPerson.Nombre = oPersonCLS.Name; oPerson.Telefono = oPersonCLS.PhoneNumber; oPerson.Correo = oPersonCLS.Email; oPerson.Appaterno = oPersonCLS.apPaterno; oPerson.Apmaterno = oPersonCLS.apMaterno; oPerson.Fechanacimiento = oPersonCLS.Birthday; } bd.SaveChanges(); response = true; } } catch (System.Exception) { } return(response); }
public bool registerProduct([FromBody] ProductCLS productCLS) { bool response = false; using (BDRestauranteContext bd = new BDRestauranteContext()) { if (productCLS.IdProduct == 0) { bd.Add(new Producto { Bhabilitado = 1, Iidcategoria = productCLS.idcategoria, Iidmarca = productCLS.idmarca, Nombre = productCLS.ProductName, Precio = productCLS.ProductPrice, Stock = productCLS.ProductStock }); } else { Producto oProduct = bd.Producto .Where(p => p.Iidproducto == productCLS.IdProduct) .FirstOrDefault(); oProduct.Iidcategoria = productCLS.idcategoria; oProduct.Iidmarca = productCLS.idmarca; oProduct.Nombre = productCLS.ProductName; oProduct.Precio = productCLS.ProductPrice; oProduct.Stock = productCLS.ProductStock; } try { bd.SaveChanges(); response = true; } catch (System.Exception) { return(false); } return(response); } }