コード例 #1
0
        public void AddLocation(Project1.BLL.Location location)
        {
            var newLocation = Mapper.Map(location);

            Context.Location.Add(newLocation);
            SaveChangesAndCheckException();
        }
コード例 #2
0
        public ActionResult Inventory(int id)
        {
            P1B.Location currentLocation = LocRepo.GetLocationById(id);
            ViewData["currentLocation"] = currentLocation.Name;

            IEnumerable <P1B.LocationInventory> locInvs = LocationInventoryRepo.GetLocationInventoryByLocationId(id)
                                                          .OrderBy(li => li.IngredientId);
            List <P1B.Ingredient> ings = IngRepo.GetIngredients().ToList();

            var viewModels = locInvs.Select(li => new LocationInventoryViewModel
            {
                LocationId   = id,
                LocationName = currentLocation.Name,
                IngredientId = li.IngredientId,
                // https://stackoverflow.com/questions/272633/add-spaces-before-capital-letters
                IngredientType   = Regex.Replace(ings.Single(i => i.Id == li.IngredientId).Type, "([a-z])([A-Z])", "$1 $2"),
                IngredientUnits  = ings.Single(i => i.Id == li.IngredientId).Units,
                IngredientAmount = li.Amount
            }).ToList();

            return(View(viewModels));
        }
コード例 #3
0
        public ActionResult Create(Project1.ViewModels.LocationViewModel viewModel)
        {
            try
            {
                if (viewModel.LocationName.Length == 0)
                {
                    string message = "The location name cannot be empty.";
                    TempData["ErrorMessage"] = message;
                    _logger.LogWarning(message);
                    return(RedirectToAction("Error", "Home"));
                }
                if (LocRepo.CheckLocationNameExists(viewModel.LocationName))
                {
                    string message = "This location name has already been used in the database.";
                    TempData["ErrorMessage"] = message;
                    _logger.LogWarning(message);
                    return(RedirectToAction("Error", "Home"));
                }

                // TODO: Add insert logic here
                var newLocation = new P1B.Location
                {
                    Name = viewModel.LocationName
                };

                // TODO: Add insert logic here
                LocRepo.AddLocation(newLocation);
                int newLocationId = LocRepo.GetLastLocationAdded();
                LocationInventoryRepo.FillLocationInventory(newLocationId);
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
コード例 #4
0
ファイル: Mapper.cs プロジェクト: ljmars2351/mattk-Project1
 public static DC.Location Map(P1B.Location location) => new DC.Location
 {
     LocationId = location.Id,
     Name       = location.Name
 };