Beispiel #1
0
        public async Task <IActionResult> Edit(EditBuildingViewModel model)
        {
            if (ModelState.IsValid)
            {
                Building building = _manager.BuildingRepository.Get(model.Id);
                if (building != null)
                {
                    if (model.Image != null)
                    {
                        if (building.Image != null)
                        {
                            DeleteFile(building.Image);
                        }
                        building.Image = await UploadFile(model.Image);
                    }

                    building.Id        = model.Id;
                    building.Name      = model.Name;
                    building.ShortDesc = model.ShortDesc;
                    building.Location  = model.Location;
                    building.Desc      = model.Desc;

                    _manager.BuildingRepository.Update(building);
                    return(Redirect("/admin/building"));
                }
            }
            return(View(model));
        }
Beispiel #2
0
        public virtual ActionResult EditBuilding(string buildingId)
        {
            var model = new EditBuildingViewModel();

            if (!string.IsNullOrWhiteSpace(buildingId))
            {
                var building = _service.GetBuilding(buildingId);
                if (building == null)
                {
                    ModelState.AddModelError("", string.Format("Invalid building {0}", buildingId));
                    return(RedirectToAction(this.Actions.Index()));
                }
                model.BuildingId  = building.BuildingId;
                model.Description = building.Description;
                model.Address1    = building.Address.Address1;
                model.Address2    = building.Address.Address2;
                model.Address3    = building.Address.Address3;
                model.Address4    = building.Address.Address4;
                model.City        = building.Address.City;
                model.State       = building.Address.State;
                model.ZipCode     = building.Address.ZipCode;
                model.CountryCode = building.Address.CountryCode;
            }
            model.CountryCodeList = (from item in _service.GetCountryList()
                                     select new SelectListItem
            {
                Text = item.Code + " : " + item.Description,
                Value = item.Code,
                Selected = item.Code == model.CountryCode
            }).ToArray();
            return(View(Views.EditBuilding, model));
        }
        public async Task <IActionResult> Edit(EditBuildingViewModel editBuildingVM)
        {
            if (ModelState.IsValid)
            {
                Building BuildingtoEdit = _context.Buildings.Single(cm => cm.ID == editBuildingVM.ID);

                BuildingtoEdit.Name        = editBuildingVM.Name;
                BuildingtoEdit.Address     = editBuildingVM.Address;
                BuildingtoEdit.PhoneNumber = editBuildingVM.PhoneNumber;

                _context.Update(BuildingtoEdit);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(editBuildingVM));
        }
Beispiel #4
0
        public async Task <IActionResult> Edit(int id)
        {
            Building building = _manager.BuildingRepository.Get(id);

            if (building == null)
            {
                return(NotFound());
            }

            EditBuildingViewModel model = new EditBuildingViewModel
            {
                Name      = building.Name,
                Desc      = building.Desc,
                ImagePath = building.Image,
                Location  = building.Location,
                ShortDesc = building.ShortDesc
            };

            return(View(model));
        }
Beispiel #5
0
        public virtual ActionResult UpdateBuilding(EditBuildingViewModel model, bool create)
        {
            if (!ModelState.IsValid)
            {
                return(View(Views.EditBuilding, model));
            }
            var address = new Address
            {
                Address1    = model.Address1,
                Address2    = model.Address2,
                Address3    = model.Address3,
                Address4    = model.Address4,
                City        = model.City,
                State       = model.State,
                ZipCode     = model.ZipCode,
                CountryCode = model.CountryCode
            };

            try
            {
                if (create)
                {
                    _service.AddBuilding(model.BuildingId, model.Description, address);
                    this.AddStatusMessage(string.Format("New Building {0} created.", model.BuildingId));
                }
                else
                {
                    _service.UpdateAddress(model.BuildingId, model.Description, address);
                    this.AddStatusMessage(string.Format("Building {0} updated.", model.BuildingId));
                }
            }
            catch (DbException ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(Views.EditBuilding, model));
            }
            return(RedirectToAction(this.Actions.Index()));
        }
        // GET: Buildings/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            //Check if user logged in:
            if (HttpContext.Session.GetString("Username") == null)
            {
                return(Redirect("/Home/Login"));
            }

            //Deny non-admins:
            FileMember user = _context.FileMembers.Single(u => u.Email == HttpContext.Session.GetString("Username"));

            if (user.Role != Role.Admin)
            {
                return(Redirect("/Buildings/Index"));
            }

            if (id == null)
            {
                return(NotFound());
            }

            var building = await _context.Buildings.SingleOrDefaultAsync(m => m.ID == id);

            if (building == null)
            {
                return(NotFound());
            }

            EditBuildingViewModel editBuildingVM = new EditBuildingViewModel
            {
                Name        = building.Name,
                Address     = building.Address,
                PhoneNumber = building.PhoneNumber,
            };

            return(View(editBuildingVM));
        }