コード例 #1
0
        public IActionResult CreateApartment(CreateApartment createApartment)
        {
            IApartment apartment = Mapper.Map <IApartment>(createApartment);

            var log = User.Identity.Name;
            var us  = Repository.Users.Search(user => user.Email == log).FirstOrDefault();

            apartment.HouseHolder = us;

            Repository.Apartments.Add(apartment);
            Repository.Save();

            var newApartment = Repository.Apartments.Search(ap => true).Last();

            var apartmentFacilities = new ApartmentFacilities
            {
                ApartmentId = newApartment.Id,
                Facilities  = Enum.GetNames(typeof(Models.Intefaces.Facility))
                              .Select(a => new Views.ViewModels.ApartmentModels.Facility
                {
                    Title = a
                })
            };

            return(View("AddFacilities", apartmentFacilities));
        }
コード例 #2
0
        public IActionResult UpdateApartment(UpdateApartment viewAapartment)
        {
            var updatedApartment = Mapper.Map <IApartment>(viewAapartment);

            var existingApartment = Repository.Apartments.FindById(updatedApartment.Id);

            existingApartment.Address        = updatedApartment.Address;
            existingApartment.Coordinates    = updatedApartment.Coordinates;
            existingApartment.Title          = updatedApartment.Title;
            existingApartment.Description    = updatedApartment.Description;
            existingApartment.CostPerNight   = updatedApartment.CostPerNight;
            existingApartment.SleepingPlaces = updatedApartment.SleepingPlaces;
            existingApartment.RoomAmount     = updatedApartment.RoomAmount;

            Repository.Apartments.Modify(existingApartment);
            Repository.Save();

            var apartmentFacilities = new ApartmentFacilities
            {
                ApartmentId = updatedApartment.Id,
                Facilities  = Enum.GetNames(typeof(Models.Intefaces.Facility))
                              .Select(a => new Views.ViewModels.ApartmentModels.Facility
                {
                    Title = a,
                })
            };

            return(View("AddFacilities", apartmentFacilities));
        }