Ejemplo n.º 1
0
        public ActionResult Neighborhood(DomesticUnitNeighborhoodViewModel viewModel)
        {
            NeighborhoodDomesticUnits relation = new NeighborhoodDomesticUnits
            {
                DomesticUnitID = viewModel.DomesticUnit.DomesticUnitID,
                NeighborhoodID = viewModel.NeighborhoodID
            };

            relation.DomesticUnit = repository.DomesticUnits
                                    .FirstOrDefault(d => d.DomesticUnitID == relation.DomesticUnitID);
            relation.Neighborhood = repository.Neighborhoods
                                    .FirstOrDefault(n => n.NeighborhoodID == relation.NeighborhoodID);

            if (ModelState.IsValid)
            {
                repository.SaveNeighborhoodDomesticUnit(relation);
                TempData["message"] = $"{relation.DomesticUnit.Name} is now located in {relation.Neighborhood.Name}";
                return(RedirectToAction("Index"));
            }
            else
            {
                // if enters here there is something wrong with the data values
                return(View(relation));
            }
        }
Ejemplo n.º 2
0
        public NeighborhoodDomesticUnits DeleteNeighborhoodDomesticUnit(Guid id)
        {
            NeighborhoodDomesticUnits dbEntry = context.NeighborhoodDomesticUnits
                                                .FirstOrDefault(n => n.DomesticUnitID == id);

            if (dbEntry != null)
            {
                context.NeighborhoodDomesticUnits.Remove(dbEntry);
                context.SaveChanges();
            }
            return(dbEntry);
        }
Ejemplo n.º 3
0
        public void SaveNeighborhoodDomesticUnit(NeighborhoodDomesticUnits neiDomesticUnit)
        {
            NeighborhoodDomesticUnits dbEntry = context.NeighborhoodDomesticUnits
                                                .FirstOrDefault(n => n.DomesticUnitID == neiDomesticUnit.DomesticUnitID);

            if (dbEntry != null)
            {
                DeleteNeighborhoodDomesticUnit(neiDomesticUnit.DomesticUnitID);
            }
            context.NeighborhoodDomesticUnits.Add(neiDomesticUnit);
            context.SaveChanges();
        }
Ejemplo n.º 4
0
        public ViewResult Neighborhood(Guid id)
        {
            DomesticUnitNeighborhoodViewModel viewModel = new DomesticUnitNeighborhoodViewModel
            {
                DomesticUnit = repository.DomesticUnits.FirstOrDefault(d => d.DomesticUnitID == id)
            };
            NeighborhoodDomesticUnits relation = repository.NeighborhoodDomesticUnitsTable
                                                 .FirstOrDefault(e => e.DomesticUnitID == viewModel.DomesticUnit.DomesticUnitID);

            viewModel.Neighborhoods = relation == null ? repository.Neighborhoods : repository.Neighborhoods.Where(n => n.NeighborhoodID != relation.NeighborhoodID);

            if (relation != null)
            {
                Neighborhood neighborhood = repository.Neighborhoods
                                            .FirstOrDefault(n => n.NeighborhoodID == relation.NeighborhoodID);
                viewModel.CurrentNeighborhoodName = neighborhood.Name;
            }
            return(View(viewModel));
        }