public IHttpActionResult UpdateStore(StoreViewModel store) { if (!ModelState.IsValid) { return(BadRequest()); } /* var storeInDb = _context.Stores.SingleOrDefault(m => m.StoreId == id);*/ using (var _context = new FoodiesEntities()) { var storeInDb = _context.Stores.Where(m => m.StoreId == store.StoreId).FirstOrDefault <Store>(); if (storeInDb == null) { return(NotFound()); } else { storeInDb.StoreName = store.StoreName; storeInDb.LocationId = store.Location.LocationId; storeInDb.Revenue = store.Revenue; _context.SaveChanges(); } } return(Ok(store)); }
public IHttpActionResult UpdateLocation(LocationViewModel location) { if (!ModelState.IsValid) { return(BadRequest()); } /* var locationInDb = _context.Locations.SingleOrDefault(m => m.LocationId == id);*/ using (var _context = new FoodiesEntities()) { var locationInDb = _context.Locations.Where(m => m.LocationId == location.LocationId).FirstOrDefault <Location>(); if (locationInDb == null) { return(NotFound()); } else { locationInDb.LocationId = location.LocationId; locationInDb.District = location.District; locationInDb.City = location.City; locationInDb.State = location.State; locationInDb.Country = location.Country; _context.SaveChanges(); } } return(Ok(location)); }
public IHttpActionResult Create(CustomerViewModel customer) { if (!ModelState.IsValid) { return(BadRequest()); } using (var _context = new FoodiesEntities()) { _context.Customers.Add(new Customer() { CustomerId = customer.CustomerId, CustomerName = customer.CustomerName, Purchase = customer.Purchase, StoreId = customer.Store.StoreId }); _context.SaveChanges(); } return(Created("custoemrs/" + customer.CustomerId.ToString(), customer)); }
public IHttpActionResult CreateStore(StoreViewModel store) { if (!ModelState.IsValid) { return(BadRequest()); } /*_context.Stores.Add(store);*/ using (var _context = new FoodiesEntities()) { _context.Stores.Add(new Store() { StoreId = store.StoreId, StoreName = store.StoreName, Revenue = store.Revenue, LocationId = store.Location.LocationId }); _context.SaveChanges(); } return(Created("stores/" + store.StoreId, store)); }
public IHttpActionResult CreateLocation(LocationViewModel location) { if (!ModelState.IsValid) { return(BadRequest()); } /*_context.Locations.Add(location);*/ using (var _context = new FoodiesEntities()) { _context.Locations.Add(new Location() { LocationId = location.LocationId, District = location.District, City = location.City, State = location.State, Country = location.Country }); _context.SaveChanges(); } return(Created("locations/" + location.LocationId, location)); }
public IHttpActionResult DeleteLocation(int id) { if (id <= 0) { return(BadRequest()); } using (var _context = new FoodiesEntities()) { var locationInDb = _context.Locations.Where(m => m.LocationId == id).FirstOrDefault(); if (locationInDb == null) { return(BadRequest()); } /* _context.Locations.Remove(locationInDb);*/ _context.Entry(locationInDb).State = EntityState.Deleted; _context.SaveChanges(); } return(Ok()); }
public IHttpActionResult DeleteCustomer(int id) { if (id <= 0) { return(BadRequest()); } Customer customerInDb = null; using (var _context = new FoodiesEntities()) { customerInDb = _context.Customers.Where(s => s.CustomerId == id).FirstOrDefault(); if (customerInDb == null) { return(NotFound()); } _context.Customers.Remove(customerInDb); _context.SaveChanges(); } return(Ok(customerInDb)); }