示例#1
0
 public Apartment(AddApartmentViewModel model, Guid ownerId)
 {
     ApartmentId = Guid.NewGuid();
     Name        = model.Name;
     LocationId  = model.LocationId;
     Images      = "burek";
     Address     = model.Address;
     OwnerId     = ownerId;
     Utilities   = model.Utilities;
     CheckIn     = model.CheckIn;
     CheckOut    = model.CheckOut;
 }
        public async Task <IActionResult> Create(AddApartmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await GetActiveUserId();

                //var owner = await _ownerService.GetOwnerByUserIdAsync(user.ToString());
                await _apartmentService.AddAsync(model, user.ToString());

                return(RedirectToAction("Index", "Owner"));
            }

            ViewBag.LocationId = new SelectList(await _locationService.GetAll(), "LocationId", "Address");
            return(View(model));
        }
示例#3
0
        public async Task <IActionResult> AddApartment(AddApartmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.GetUserAsync(HttpContext.User);

                var apartment = new Apartment
                {
                    Address          = model.Address,
                    Advance          = model.Advance,
                    City             = model.City,
                    ConstructionYear = model.ConstructionYear,
                    FullDescription  = model.Description,
                    Price            = model.Price,
                    SquareMetrage    = model.SquareMetrage,
                    Floor            = model.Floor,
                    MainPageDisplay  = model.MainPageDisplay,
                    Name             = model.Name,
                    NumberOfRooms    = model.NumberOfRooms,
                    HaveFurnishings  = model.HaveFurnishings,
                    HaveBasement     = model.HaveBasement,
                    HaveBalcony      = model.HaveBalcony,
                    PropertyType     = PropertyType.Mieszkanie,
                    Images           = new List <Photo>(),
                    OwnerID          = user.Id,
                    AgencyName       = model.AgencyName
                };

                Advertisement adv = new Advertisement
                {
                    PropertyType = PropertyType.Dom,
                    DateAdded    = DateTime.Now,
                    EndDate      = adManager.SetExpirationDate(model.AdvLength),
                    Name         = model.Name,
                    User         = user,
                    Apartment    = apartment
                };
                string mainName;
                string uploadsDirectory = Path.Combine(hostingEnvironment.WebRootPath, "images");
                if (model.MainImage != null)
                {
                    mainName = adManager.ReturnUniqueName(model.MainImage);
                    var photo = new Photo
                    {
                        PhotoName = mainName,
                        PhotoPath = uploadsDirectory
                                    //If using HasOne (OneToOne Relationship) instead of Owns One(OwnedType)
                                    //ApartmentPrincipal = apartment
                    };
                    adManager.UploadPhoto(model.MainImage, uploadsDirectory, mainName);
                    apartment.MainImageName = photo.PhotoName;
                }
                List <string> photoNames = new List <string>();
                if (model.Images != null && model.Images.Count > 0)
                {
                    var galleryPath = Path.Combine(hostingEnvironment.WebRootPath, "images", "Gallery_ap_" + $"{model.Name}");
                    if (!Directory.Exists(galleryPath))
                    {
                        Directory.CreateDirectory(galleryPath);
                    }
                    foreach (var photo in model.Images)
                    {
                        string name = adManager.ReturnUniqueName(photo);
                        photoNames.Add(name);
                        adManager.UploadPhoto(photo, galleryPath, name);
                    }
                    foreach (var photoName in photoNames)
                    {
                        apartment.Images.Add(new Photo {
                            PhotoName = photoName, PhotoPath = galleryPath                              /*ApartmentsPrincipal =  apartment*/
                        });
                    }
                }
                adv.Apartment = apartment;
                unit.AdvertismentRepository.AddAdvertisement(adv);
                unit.SaveData();
                if (model.MainPageDisplay == true)
                {
                    return(RedirectToAction("Promote", "Advertisements", adv));
                }
            }
            return(RedirectToAction("Success", "Customers"));
        }
        public async Task AddAsync(AddApartmentViewModel apartment, string userId)
        {
            var owner = await _ownerService.GetOwnerByUserIdAsync(userId);

            _apartmentRepository.Insert(new Apartment(apartment, owner.OwnerId));
        }