コード例 #1
0
        public ActionResult NewStep3(LocationNewFacilitiesViewModel model)
        {
            var locationFacilitiesRepository = _unitOfWork.LocationFacilitiesRepository;

            ViewBag.Facilities = locationFacilitiesRepository.GetAll();

            return(View());
        }
コード例 #2
0
        public ActionResult PostNewStep3(LocationNewFacilitiesViewModel model)
        {
            if (!VerifyDataExists(step: 3))
            {
                return(RedirectToAction("New"));
            }

            if (!ModelState.IsValid)
            {
                return(NewStep3(model));
            }

            TempData["NewLocationStepThreeData"] = model;

            return(RedirectToAction("NewStep4", "Locations"));
        }
コード例 #3
0
        public ActionResult NewStep4(LocationNewImagesViewModel model)
        {
            if (!VerifyDataExists(step: 4))
            {
                return(RedirectToAction("New"));
            }

            LocationNewGeneralViewModel    generalData    = (LocationNewGeneralViewModel)TempData["NewLocationStepOneData"];
            LocationNewAddressViewModel    addressData    = (LocationNewAddressViewModel)TempData["NewLocationStepTwoData"];
            LocationNewFacilitiesViewModel facilitiesData = (LocationNewFacilitiesViewModel)TempData["NewLocationStepThreeData"];

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                var locationsRepository           = _unitOfWork.LocationsRepository;
                var locationsFacilitiesRepository = _unitOfWork.LocationFacilitiesRepository;

                DbLocation dbLocation = new DbLocation();
                dbLocation.Name              = generalData.Name;
                dbLocation.Description       = generalData.Description;
                dbLocation.Capacity          = generalData.Capacity;
                dbLocation.Organisation      = generalData.Organisation;
                dbLocation.PricePerDay       = generalData.PricePerDay;
                dbLocation.AddressCity       = addressData.AddressCity;
                dbLocation.AddressNumber     = addressData.AddressNumber;
                dbLocation.AddressPostalCode = addressData.AddressPostalCode;
                dbLocation.AddressProvince   = addressData.AddressProvince;
                dbLocation.AddressStreet     = addressData.AddressStreet;
                dbLocation.CreatedByUserId   = ((AuthenticatedUser)User).Id;

                dbLocation.Facilities = facilitiesData.SelectedDatabaseIds.Select(x =>
                {
                    DbLocationFacility facility = new DbLocationFacility {
                        Id = x
                    };
                    locationsFacilitiesRepository.Attach(facility);
                    return(facility);
                }).ToList();

                // Save the location first because we want the location Id to store our images
                locationsRepository.Insert(dbLocation);

                string locationImagesBasePath = HostingEnvironment.MapPath("~/Resources/Location/" + dbLocation.Id + "/Images/");
                Directory.CreateDirectory(locationImagesBasePath);

                string bannerImageFileName = null;
                foreach (var file in model.Images)
                {
                    if (file == null || file.ContentLength <= 0)
                    {
                        continue;
                    }

                    string fileExtension = Path.GetExtension(file.FileName).ToLower();
                    if (fileExtension != ".jpg" && fileExtension != ".jpeg" && fileExtension != ".png")
                    {
                        continue;
                    }

                    string fileName = Path.GetFileName(file.FileName);
                    string filePath = Path.Combine(locationImagesBasePath, fileName);
                    file.SaveAs(filePath);

                    if (bannerImageFileName == null)
                    {
                        bannerImageFileName = fileName;
                    }
                }

                dbLocation.BannerImageFileName = bannerImageFileName;
                locationsRepository.Update(dbLocation);

                TempData["AlertType"]    = "success";
                TempData["AlertMessage"] = "De locatie is succesvol aangemaakt";

                return(RedirectToAction("Details", "Locations", new { id = dbLocation.Id, Area = string.Empty }));
            }
            catch
            {
                TempData["AlertType"]    = "danger";
                TempData["AlertMessage"] = "Er is iets fout gelopen tijdens het verwerken van de nieuwe locatie!";

                // We've previously accessed our data, indicate that we want to keep it
                TempData["NewLocationStepOneData"]   = generalData;
                TempData["NewLocationStepTwoData"]   = addressData;
                TempData["NewLocationStepThreeData"] = facilitiesData;

                return(View(model));
            }
        }