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 Apartment Post(ApartmentDTO value) { Apartment model = new Apartment() { apartmentName = value.apartmentName, numberOfRooms = value.numberOfRooms, description = value.description, pricePerNight = value.pricePerNight, propertyId = value.propertyId }; return(IApartmentRepository.Create(model)); }
public ICommandResult Handle(CreateApartmentCommand command) { // Fail Fast Validation command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Ops, erro ao cadastrar apartamento.", command.Notifications)); } try { // Recupera condomínio var condominium = _condominiumRepository.GetById(command.CondominiumId.Value, command.User); if (condominium == null) { return(new GenericCommandResult(false, "Ops, erro ao cadastrar apartamento.", "Condomínio não encontrado")); } // Cria apartamento var apartment = new Apartment(condominium, command.Number, command.Block, command.User); if (command.Residents.Count > 0) { foreach (var resident in command.Residents) { var res = _residentRepository.GetById(resident, command.User); apartment.AddResident(res); } } // Salva morador _repository.Create(apartment); var apartmentResult = new ApartmentCommandResult { Block = apartment.Block, //Condominium = apartment.Condominium.Name, Number = apartment.Number, User = apartment.User }; return(new GenericCommandResult(true, "Apartamento salvo com sucesso!", apartmentResult)); } catch (Exception ex) { return(new GenericCommandResult(false, "Erro inesperado!", ex.Message)); } }
public async Task <ActionResult <Apartment> > CreateApartment([FromBody] CreateApartmentRequest request) { try { var apartment = new Apartment { Title = request.Title, Address = request.Address, FitsPeople = request.FitsPeople, EmployeeTravels = new List <EmployeeTravel>() }; return(Ok(await _apartmentRepository.Create(apartment))); } catch (ArgumentException) { return(Conflict()); } }
public ActionResult AddApartment(Apartment apartment) { apartment.HomeownerId = _homeowner.Id; apartmentRepository.Create(apartment); return(RedirectToAction("Apartments")); }