public void WriteCustomerToDB([FromBody] Customer value) { var db = new CustomerModelDataContext(); db.Customers.InsertOnSubmit(value); db.SubmitChanges(); }
public List <Customer> GetAll() { var db = new CustomerModelDataContext(); IEnumerable <Customer> queryResult; queryResult = db.Customers.OrderBy(o => o.CompanyId); return(queryResult.ToList <Customer>()); }
public Customer Get(string key = null) { var db = new CustomerModelDataContext(); int keyValueAsInt = Int32.Parse(key); IEnumerable <Customer> queryResult; queryResult = db.Customers.Where(o => o.CompanyId == keyValueAsInt); var customer = queryResult.FirstOrDefault(); return(customer); }
public void UpdateOrderInDB([FromBody] Customer value, string key) { var db = new CustomerModelDataContext(); int keyValueAsInt = Int32.Parse(key); var query = from Customer in db.Customers where Customer.CompanyId == keyValueAsInt select Customer; var orderInDB = query.First(); #region changeDb if (orderInDB.CompanyName != value.CompanyName) { orderInDB.CompanyName = value.CompanyName; } if (orderInDB.ContactPerson != value.ContactPerson) { orderInDB.ContactPerson = value.ContactPerson; } if (orderInDB.Adress != value.Adress) { orderInDB.Adress = value.Adress; } if (orderInDB.Email != value.Email) { orderInDB.Email = value.Email; } if (orderInDB.PhoneNumber != value.PhoneNumber) { orderInDB.PhoneNumber = value.PhoneNumber; } #endregion db.SubmitChanges(); }