Example #1
0
        public ActionResult Edit(string hotelId)
        {
            //find the hotel in the repository
            // Hotel h = hotelRepo.FindByCode(hotelId);
            Hotel h = hotelRepo.FindAll().FirstOrDefault(t => t.HotelId.Equals(hotelId));

            //making the lists so that you only go to the Repo's once
            List <ContactPerson> contact = contactRepo.FindAll().OrderBy(t => t.LastName).ToList();
            List <Branch>        branch  = branchRepo.FindAll().OrderBy(t => t.Name).ToList();
            List <Owner>         owner   = ownerRepo.FindAll().OrderBy(t => t.LastName).ToList();
            List <Status>        status  = statusRepo.FindAll().OrderBy(t => t.St).ToList();

            //check if the hotel exist (normally this can never give null unless DB failure)
            if (h == null)
            {
                return(HttpNotFound());
            }

            //Use a viewmodel to display al the details of the hotel
            EditHotelViewModel ehvm = new EditHotelViewModel(h)
            {
                //select the active branch
                SelectedBranchId = branch.Where(t => t.BranchId == h.Branch.BranchId).FirstOrDefault().Name,
                //fill the list with all the branches
                Branch = branch.Select(t => new SelectListItem
                {
                    Value = t.BranchId.ToString(),
                    Text  = t.Name
                }),
                //repeat for al the other lists

                //Contactperson
                //it doesn't matter with the selectedId if you use the id of the name
                SelectedContactPersonId = contact.Where(t => t.ContactPersonId == h.ContactPerson.ContactPersonId).FirstOrDefault().ContactPersonId.ToString(),
                ContactPerson           = contact.Select(t => new SelectListItem
                {
                    Value = t.ContactPersonId.ToString(),
                    Text  = t.LastName + " " + t.FirstName
                }),

                //Owner
                SelectedOwnerId = owner.Where(t => t.OwnerId == h.Owner.OwnerId).FirstOrDefault().OwnerId.ToString(),
                Owner           = owner.Select(t => new SelectListItem
                {
                    Value = t.OwnerId.ToString(),
                    Text  = t.LastName + " " + t.FirstName
                }),

                //status
                SelectedStatusId = status.Where(t => t.St == h.Status.St).FirstOrDefault().ToString(),
                Status           = status.Select(t => new SelectListItem
                {
                    Value = t.St,
                    Text  = t.St
                })
            };

            return(View(ehvm));
        }
Example #2
0
        // GET: Settings
        public ActionResult Index()
        {
            SettingsViewModel svm = new SettingsViewModel(branchRepo.FindAll().ToList(), contactRepo.FindAll().ToList(), ownerRepo.FindAll().ToList(), statusRepo.FindAll().ToList());

            return(View(svm));
        }