public ActionResult Edit(int id, [Bind("Name, Id")] LocationViewModel viewLocation, IFormCollection collection) { // get the current id from tempdata to ensure the user hasn't modified the id that the page put out int tdId = (int)TempData.Peek("Location"); if (tdId != id && tdId != viewLocation.Id) { // *ER add error message return(RedirectToAction(nameof(Index))); } // check modelstate if (!ModelState.IsValid) { return(View(viewLocation)); } try { var location = new Library.Location(viewLocation.Name, viewLocation.Id); _locationRepository.Update(location); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public CustomerViewModel(Library.Customer customer, Library.Location store) { Id = customer.Id; FullName = customer.FirstName + ' ' + customer.LastName; Birthday = customer.Birthday; Store = store; }
public Library.Order GetOrder(int orderId) { Order order = db.Order.Include(a => a.User).Include(b => b.Location).Include("OrderContent.Content").First(o => o.OrderId == orderId); Library.Location l = Mapper.Map(order.Location); Library.User u = Mapper.Map(order.User); Dictionary <Pizza, int> pizzas = new Dictionary <Pizza, int>(); foreach (OrderContent oc in order.OrderContent) { Pizza p = new Pizza() { Name = oc.Content.Name, Price = oc.Content.Price }; pizzas[p] = oc.Amount; } Library.Order result = new Library.Order { OrderId = order.OrderId, User = u, Location = l, Contents = pizzas, OrderTime = order.OrderTime }; return(result); }
private List <Library.Order> GetOrderHistory(List <Order> os) { List <Library.Order> result = new List <Library.Order>(); foreach (var o in os) { Library.Location l = Mapper.Map(o.Location); Library.User u = Mapper.Map(o.User); Dictionary <Pizza, int> pizzas = new Dictionary <Pizza, int>(); foreach (OrderContent oc in o.OrderContent) { Pizza p = new Pizza() { Name = oc.Content.Name, Price = oc.Content.Price }; pizzas[p] = oc.Amount; } Library.Order tempOrder = new Library.Order() { OrderId = o.OrderId, User = u, Location = l, Contents = pizzas, OrderTime = o.OrderTime }; result.Add(tempOrder); } return(result); }
//Data object--> Entity public static Entities.Locations MapLocationWithEF(Library.Location OLocation) { return(new Entities.Locations { Located = OLocation.Locate, Lid = OLocation.LID, Inventory = OLocation.Inventory }); }
public static Location Map(Library.Location location) => new Location { Locationid = location.Locationid, Street = location.Street, State = location.State, City = location.City, // Pizzastore = Map(location.Pizzastore), // Customer = Map(location.Customer).ToList(), // Orderdetails = Map(location.Orderdetails).ToList(), };
public void Update(Library.Location location) { // get the location from db var dbLoc = _context.Locations.First(l => l.Id == location.Id); // update name dbLoc.Name = location.Name; // save changes _context.SaveChanges(); }
public void Create(Library.Location location) { var loc = new Location() { Name = location.Name }; _context.Add(loc); _context.SaveChanges(); }
public static Library.Location MapLocation(Entities.Locations dbmodel) { Library.Location result = new Library.Location { Id = dbmodel.LocationId, Name = dbmodel.Name, Inventory = dbmodel.InventoryItems.Select(MapInventoryItem).ToList() }; return(result); }
/*------------------------------------------------------*/ /* Location mapping */ public static Entities.Locations MapLocation(Library.Location model) { Entities.Locations result = new Entities.Locations { LocationId = model.Id, Name = model.Name, //InventoryItems = model.Inventory.Select(i => MapInventoryItem(model,i)).ToList() }; return(result); }
public void AddLocation(Library.Location location) { using var context = new project0Context(_dbContext); var dbLocation = new Library.Location() { Name = location.Name, Address = location.Address, City = location.City, State = location.State }; }
/// <summary> /// Given a business model inventory, update inverntory items in database /// </summary> /// <param name="items"></param> public void UpdateInventory(IEnumerable <Library.Item> blInventory, Library.Location blLocation) { //s_logger.Info($"Updating inventory"); // populate list with mapped items foreach (Library.Item item in blInventory) { // find associated inventory item using item id var newEntity = Mapper.MapInventoryItem(blLocation, item); var oldEntity = dbcontext.InventoryItems.Where(ii => ii.LocationId == newEntity.LocationId && ii.ProductId == newEntity.ProductId).FirstOrDefault(); oldEntity.Quantity = newEntity.Quantity; } }
public static Location Map(Library.Location location) => new Location { //Id = location.id Name = location.Name //List < Locationingredient > result = new List<Locationingredient>(); /* * foreach(KeyValuePair<Ingredient, int> pair in location.Inventory) * { * result.Add(new Locationingredient() { }) * } */ };
/*------------------------------------------------------*/ /* Item to InventoryItems Mapping */ public static Entities.InventoryItems MapInventoryItem(Library.Location modelL, Library.Item modelP) { Entities.InventoryItems result = new Entities.InventoryItems { Product = MapProduct(modelP.Product), ProductId = modelP.Product.ID, Quantity = modelP.Quantity, LocationId = modelL.Id, Location = MapLocation(modelL) }; return(result); }
// GET: Locations/Details/5 public ActionResult Details(int?id) { if (id == null) { return(NotFound()); } Library.Location location = Repo.SearchLocationsById((int)id); List <Library.Inventory> StoreInv = new List <Library.Inventory>(); if (location == null) { return(NotFound()); } LocationViewModel model = new LocationViewModel { LocationId = location.LocId, Address = location.StreetAddress, City = location.City, State = location.State, Zip = location.Zip, Prod = Repo.GetProducts().ToList(), Inventory = Repo.GetInventory(location.LocId).ToList() }; bool hs = true; for (int x = 0; x < model.Prod.Count; x++) { Library.Inventory Inv = new Library.Inventory(); Inv.ProductId = model.Prod[x].ProdId; hs = model.Inventory.Any( y => y.LocationId == model.LocationId && y.ProductId == model.Prod[x].ProdId); if (hs == true) { Inv.Quantity = model.Inventory.First( y => y.LocationId == model.LocationId && y.ProductId == model.Prod[x].ProdId).Quantity; } else { Inv.Quantity = 0; } Inv.LocationId = model.LocationId; StoreInv.Add(Inv); } model.StoreInv = StoreInv; return(View(model)); }
public bool UpdateLocation(Library.Location location) { ////_db.Entry(_db.Restaurant.Find(restaurant.Id)).CurrentValues.SetValues(Mapper.Map(restaurant)); var temp = db.Location.Include("Locationingredient.Ingredient").First(c => c.LocationId == location.LocationId); if (temp != null) { Location updated = getNewLocation(location); updated.LocationId = location.LocationId; db.Entry(temp).CurrentValues.SetValues(updated); db.SaveChanges(); return(true); } return(false); }
//public void UpdateUser() public void AddLocation(Library.Location location) { Location l = getNewLocation(location); db.Add(l); db.SaveChanges(); //foreach(var pair in location.Inventory) //{ // Ingredient i = db.Ingredient.First(a => a.Name == pair.Key.Name); // if(i == null) // { // i = new Ingredient() { Name = pair.Key.Name }; // } // l.Locationingredient.Add(new Locationingredient() { Ingredient = i, Location = l, Quantity = pair.Value }); //} location.LocationId = l.LocationId; }
public List <Library.Inventory> GetInventoryByLocation(Library.Location location) { using var context = new project0Context(_dbContext); var dbInventroy = context.Inventories .Where(o => o.LocationId == location.LocationId) .Include(o => o.Product) .ToList(); var inventory = new List <Library.Inventory>(); foreach (var inv in dbInventroy) { var newProduct = new Library.Inventory(inv.LocationId, inv.Product.ProductId, inv.Quantity); newProduct.ProductId = inv.ProductId; inventory.Add(newProduct); } return(inventory); }
public ActionResult Create([Bind("Name")] LocationViewModel viewLocation, IFormCollection collection) { if (!ModelState.IsValid) { return(View(viewLocation)); } try { // give the id as 1 just to get it into the system // the create repo does not use that id to form a new DB entry var location = new Library.Location(viewLocation.Name, 1); _locationRepository.Create(location); return(RedirectToAction(nameof(Index))); } catch { ModelState.AddModelError("", "There was a problem Creating the Location"); return(View(viewLocation)); } }
public List <Library.Location> GetLocations() { List <Location> locations = db.Location.Include("Locationingredient.Ingredient").ToList(); List <Library.Location> result = new List <Library.Location>(); foreach (var l in locations) { Dictionary <Library.Ingredient, int> tempInventory = new Dictionary <Library.Ingredient, int>(); foreach (var i in l.Locationingredient) { tempInventory[Mapper.Map(i.Ingredient)] = i.Quantity; } Library.Location temp = new Library.Location() { LocationId = l.LocationId, Name = l.Name, Inventory = tempInventory }; result.Add(temp); } return(result); }
private Location getNewLocation(Library.Location location) { Location newLoc = Mapper.Map(location); foreach (var pair in location.Inventory) { Ingredient i = db.Ingredient.Find(pair.Key.IngredientId); //probably shouldnt do this if (i == null) { i = new Ingredient() { Name = pair.Key.Name }; } newLoc.Locationingredient.Add(new Locationingredient() { Ingredient = i, Location = newLoc, Quantity = pair.Value }); } return(newLoc); }
/// <summary> /// Get a Location by ID. /// </summary> /// <returns>The Location</returns> public Library.Location GetLocationById(int locationId) { using var context = new project0Context(_dbContext); var dbLocation = context.Locations .Where(o => o.LocationId == locationId) .FirstOrDefault(); var location = new Library.Location() { LocationId = dbLocation.LocationId, Name = dbLocation.Name, Address = dbLocation.Address, City = dbLocation.City, State = dbLocation.State }; var locationInventory = GetInventoryByLocation(location); foreach (var product in locationInventory) { location.Inventory.Add(product); } return(location); }
public ActionResult Edit([FromRoute] int id, Location location) { try { if (ModelState.IsValid) { var libLocation = new Library.Location { Id = id, Name = location.Name, InventoryId = location.InventoryId }; Repo.UpdateLocation(libLocation); Repo.Save(); return(RedirectToAction(nameof(Index))); } return(View(location)); } catch (Exception) { return(View(location)); } }
//public void UpdateUser() public void AddLocation(Library.Location location) { Location l = Mapper.Map(location); db.Add(l); db.SaveChanges(); foreach (var pair in location.Inventory) { Ingredient i = db.Ingredient.First(a => a.Name == pair.Key.Name); if (i == null) { i = new Ingredient() { Name = pair.Key.Name }; } l.Locationingredient.Add(new Locationingredient() { Ingredient = i, Location = l, Quantity = pair.Value }); } location.LocationId = l.LocationId; db.SaveChanges(); }
public static StoreLocation Map(Library.Location location) => new StoreLocation { LocationId = location.LocationId, LocationName = location.Name, LocationAddress = location.Address };
public static Entities.Locations Map(Library.Location locale) => new Entities.Locations { LocationId = locale.Id, Name = locale.Name, Orders = Map(locale.Orders).ToList() };
public static ModelLocation Map(Library.Location location) => new ModelLocation { LocationId = location.LocationId, Name = location.Name, Inventory = location.Inventory != null?Map(location.Inventory) : null };
public static Store Map(Library.Location store) => new Store { Id = store.LocationId, Name = store.Name, };
public static Entities.Location Map(Library.Location location) => new Entities.Location { LocationId = location.ID, Inventory = Map(location.Inventory).ToList() };
public StoreViewModel(Library.Location store) { Id = store.LocationId; Name = store.Name; }