public bool Create(ApartmentCreateViewModel createVM, string userId, string userName, string folderName) { Apartment create = new Apartment(); create.AvailableToGuestId = createVM.AvailableToGuestId; create.Description = createVM.Description; create.Price = createVM.Price; create.TypeOfHousingId = createVM.TypeOfHousingId; create.Address = createVM.Street + " " + createVM.StreetNumber; create.MaxNumberOfGuests = createVM.MaxNumberOfGuests; create.UserProfileId = userId; if (createVM.FletNumber != null) { create.Address += "/" + createVM.FletNumber; } FillApartmentCountryAndCity(create, createVM.CityAndCountry); if (createVM.SelectedApartmentComfortsId != null) { for (int i = 0; i < createVM.SelectedApartmentComfortsId.Count; i++) { create.ApartmentComforts.Add(apartmentComfortRep.GetById(Int32.Parse(createVM.SelectedApartmentComfortsId[i]))); } } apartmentRep.Create(create); apartmentRep.SaveChanges(); FillApartmentImages(createVM.images.Length, createVM.images, create.Id, userName, folderName); return(true); }
public ApartmentCreateViewModel GetCreateApartment() { ApartmentCreateViewModel apartmentCreate = new ApartmentCreateViewModel(); apartmentCreate.AvailableToGuest = availableToGuestService.GetAll().ToList(); apartmentCreate.TypeOfHousing = typeOfHousingService.GetAll().ToList(); apartmentCreate.ApartmentComforts = apartmentComfortService.GetAll().ToList(); return(apartmentCreate); }
public ActionResult Create(ApartmentCreateViewModel apartmentCreateVM) { if (ModelState.IsValid) { if (apartmentCreateVM.images.Length == 1 && apartmentCreateVM.images[0] == null) { ModelState.AddModelError("Images", "Add minimum 1 photo"); return(View(apartmentCreateVM)); } bool addConfirm = apartmentService.Create(apartmentCreateVM, User.Identity.GetUserId(), User.Identity.Name, Server.MapPath("~/Images")); if (!addConfirm) { ModelState.AddModelError("Name", "Name already exists"); return(View(apartmentCreateVM)); } return(RedirectToAction("Index", "Home")); } return(View(apartmentCreateVM)); }
public ActionResult Create() { ApartmentCreateViewModel apartmentCreateVM = apartmentService.GetCreateApartment(); return(View(apartmentCreateVM)); }