public CustomerModelResponse GetCustomer(int id) { using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context()) { Customer customer = context.Customers.Find(id); return(new CustomerModelResponse(customer)); } }
public IEnumerable <PhoneModelResponse> GetAllPhones() { using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context()) { List <PhoneModelResponse> list = new List <PhoneModelResponse>(); foreach (Phone phone in context.Products.OfType <Phone>().ToArray()) { list.Add( new PhoneModelResponse(phone) ); } return(list); } }
public bool DeleteCustomer(int id) { using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context()) { Customer customer = context.Customers.First(c => c.Id == id); if (customer != null) { context.Customers.Remove(customer); context.SaveChanges(); return(true); } return(false); } }
public IEnumerable <CustomerModelResponse> GetAllCustomers() { using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context()) { List <CustomerModelResponse> list = new List <CustomerModelResponse>(); foreach (Customer customer in context.Customers.ToArray()) { list.Add( new CustomerModelResponse(customer) ); } return(list); } }
public PhoneModelResponse GetPhone(int id) { using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context()) { var phone = context.Products.OfType <Phone>().First(p => p.Id == id); if (phone != null) { return(new PhoneModelResponse(phone)); } else { return(null); } } }
public int CreateCustomer(CustomerModelResquest data) { if (data != null && data.IsValidate()) { Customer customer = data.ToCustomer(); using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context()) { context.Customers.Add(customer); context.SaveChanges(); return(customer.Id); } } return(0); }
public int CreatePhone(PhoneModelRequest data) { if (data != null && data.IsValidate()) { Phone phone = data.ToPhone(); using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context()) { context.Products.Add(phone); context.SaveChanges(); return(phone.Id); } } return(0); }
public List <PhoneModelResponse> GetAllPhonesOfProduction(int id) { using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context()) { List <PhoneModelResponse> list = new List <PhoneModelResponse>(); var products = context.Productions.Include(p => p.Products).First(p => p.Id == id).Products; if (products != null) { foreach (Phone phone in products) { list.Add( new PhoneModelResponse(phone) ); } } return(list); } }
public bool UpdateCustomer(int id, CustomerModelResquest data) { if (data != null && data.IsValidate()) { using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context()) { Customer customer = context.Customers.First(c => c.Id == id); if (customer != null) { customer.FirstName = data.FirstName; customer.LastName = data.LastName; customer.Email = data.Email; } context.SaveChanges(); return(true); } } return(false); }
public bool UpdatePhone(int id, PhoneModelRequest data) { if (data != null && data.IsValidate()) { using (DataLayer.DataAccess.Context context = new DataLayer.DataAccess.Context()) { Phone phone = context.Products.OfType <Phone>().First(p => p.Id == id); if (phone != null) { //update data } context.SaveChanges(); return(true); } } return(false); }