public IHttpActionResult GetProduct(DataBase.Model.ViewModel.ProductViewModel model) { List <DataBase.Model.ViewModel.ProductViewModel> list = new List <DataBase.Model.ViewModel.ProductViewModel>(); try { using (DataBase.Model.CustomerServicesEntities db = new DataBase.Model.CustomerServicesEntities()) { list = (from d in db.Product select new DataBase.Model.ViewModel.ProductViewModel { serviceId = d.serviceId, productName = d.productName, productNameType = d.productNameType, numeracioTerminal = d.numeracioTerminal, soldAt = d.soldAt, customerId = d.customerId }).ToList(); } return(Ok(list)); } catch (Exception e) { throw new Exception("Se ha producido un error al hacer el método GetProduct: " + e); } }
public IHttpActionResult GetCustomer(DataBase.Model.ViewModel.CustomerViewModel model) { List <DataBase.Model.ViewModel.CustomerViewModel> list = new List <DataBase.Model.ViewModel.CustomerViewModel>(); try { using (DataBase.Model.CustomerServicesEntities db = new DataBase.Model.CustomerServicesEntities()) { list = (from d in db.Customer select new DataBase.Model.ViewModel.CustomerViewModel { customerId = d.customerId, docType = d.docType, docNum = d.docNum, email = d.email, givenName = d.givenName, familyName = d.familyName, phone = d.phone }).ToList(); } return(Ok(list)); } catch (Exception e) { throw new Exception("Se ha producido un error al hacer el método GetCustomer: " + e); } }
public IHttpActionResult AddProduct(DataBase.Model.ViewModel.ProductViewModel model) { try { using (DataBase.Model.CustomerServicesEntities db = new DataBase.Model.CustomerServicesEntities()) { var product = new DataBase.Model.Product(); product.serviceId = model.serviceId; product.productName = model.productName; product.productNameType = model.productNameType; product.numeracioTerminal = model.numeracioTerminal; product.soldAt = model.soldAt; product.customerId = model.customerId; db.Product.Add(product); db.SaveChanges(); return(Ok("Producto añadido")); } } catch (Exception e) { throw new Exception("Se ha producido un error al hacer el método AddProduct: " + e); } }
public IHttpActionResult AddCustomer(DataBase.Model.ViewModel.CustomerViewModel model) { try { using (DataBase.Model.CustomerServicesEntities db = new DataBase.Model.CustomerServicesEntities()) { var customer = new DataBase.Model.Customer(); customer.customerId = model.customerId; customer.docType = model.docType; customer.docNum = model.docNum; customer.email = model.email; customer.customerId = model.customerId; customer.givenName = model.givenName; customer.familyName = model.familyName; customer.phone = model.phone; db.Customer.Add(customer); db.SaveChanges(); } return(Ok("Customer añadido.")); } catch (Exception e) { throw new Exception("Se ha producido un error al hacer el método AddCustomer: " + e); } }