コード例 #1
0
        public IActionResult Edit(EditRoomViewModel model)
        {
            if (ModelState.IsValid)
            {
                var room = unit.RoomRepository.GetRoom(model.Id);

                room.Address           = model.Address;
                room.Advance           = model.Advance;
                room.City              = model.City;
                room.ConstructionYear  = model.ConstructionYear;
                room.FullDescription   = model.Description;
                room.Price             = model.Price;
                room.SquareMetrage     = model.SquareMetrage;
                room.Name              = model.Name;
                room.Floor             = model.Floor;
                room.HaveFurnishings   = model.HaveFurnishings;
                room.NumberOfFlatmates = model.NumberOfFlatmates;
                room.TotalArea         = model.TotalArea;

                if (model.MainImage != null)
                {
                    System.IO.File.Delete(Path.Combine(room.MainImage.PhotoPath, room.MainImage.PhotoName));
                    string name = manager.ReturnUniqueName(model.MainImage);
                    manager.UploadPhoto(model.MainImage, Path.Combine(hostEnvironment.WebRootPath, "images"), name);
                    room.MainImage = new Photo
                    {
                        PhotoName = name,
                        PhotoPath = Path.Combine(hostEnvironment.WebRootPath, "images")
                    };
                    room.MainImageName = name;
                }

                if (model.Images != null)
                {
                    List <string> photoNames = new List <string>();

                    foreach (var image in room.Images)
                    {
                        System.IO.File.Delete(Path.Combine(image.PhotoPath, image.PhotoName));
                    }
                    foreach (var photo in model.Images)
                    {
                        var name = manager.ReturnUniqueName(photo);
                        photoNames.Add(name);
                        manager.UploadPhoto(photo, room.Images.FirstOrDefault().PhotoPath, name);
                    }
                    foreach (var photoName in photoNames)
                    {
                        room.Images.Add(new Photo {
                            PhotoName = photoName, PhotoPath = Path.Combine(hostEnvironment.WebRootPath, "images")
                        });
                    }
                }

                unit.RoomRepository.EditRoom(room);
                unit.SaveData();
                return(RedirectToAction("Success", "Customers"));
            }
            return(View(model));
        }
コード例 #2
0
        public IActionResult Edit(EditCommercialSpaceViewModel model)
        {
            if (ModelState.IsValid)
            {
                var cs = unit.CommercialSpaceRepository.GetCommercialSpace(model.Id);

                cs.Name             = model.Name;
                cs.Price            = model.Price;
                cs.Address          = model.Address;
                cs.NumberOfRooms    = model.NumberOfRooms;
                cs.SquareMetrage    = model.SquareMetrage;
                cs.City             = model.City;
                cs.ConstructionYear = model.ConstructionYear;
                cs.Floor            = model.Floor;
                cs.Advance          = model.Advance;
                cs.FullDescription  = model.Description;

                if (model.MainImage != null)
                {
                    string filePath = Path.Combine(hostingEnvironment.WebRootPath,
                                                   "images", model.MainImageName);
                    System.IO.File.Delete(filePath);
                    string name = manager.ReturnUniqueName(model.MainImage);
                    manager.UploadPhoto(model.MainImage, Path.Combine(hostingEnvironment.WebRootPath,
                                                                      "images"), name);
                    cs.MainImage = new Photo
                    {
                        PhotoName = name,
                        PhotoPath = Path.Combine(hostingEnvironment.WebRootPath, "images")
                    };
                    cs.MainImageName = name;
                }
                if (model.Images != null)
                {
                    List <string> photoNames = new List <string>();

                    foreach (var image in cs.Images)
                    {
                        System.IO.File.Delete(image.PhotoPath);
                    }
                    foreach (var photo in model.Images)
                    {
                        var name = manager.ReturnUniqueName(photo);
                        photoNames.Add(name);
                        manager.UploadPhoto(photo, cs.Images.FirstOrDefault().PhotoPath, name);
                    }
                    foreach (var photoName in photoNames)
                    {
                        cs.Images.Add(new Photo {
                            PhotoName = photoName, PhotoPath = Path.Combine(hostingEnvironment.WebRootPath, "images")
                        });
                    }
                }

                unit.CommercialSpaceRepository.EditCommercialSpace(cs);
                unit.SaveData();
                return(RedirectToAction("Success", "Customers"));
            }

            return(View(model));
        }
コード例 #3
0
        public IActionResult Edit(EditApartmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var editApartment = unit.ApartmentRepository.GetApartment(model.Name);

                editApartment.Name             = model.Name;
                editApartment.Address          = model.Address;
                editApartment.Advance          = model.Advance;
                editApartment.City             = model.City;
                editApartment.ConstructionYear = model.ConstructionYear;
                editApartment.FullDescription  = model.Description;
                editApartment.Price            = model.Price;
                editApartment.SquareMetrage    = model.SquareMetrage;
                editApartment.Floor            = model.Floor;
                editApartment.MainPageDisplay  = model.MainPageDisplay;
                editApartment.NumberOfRooms    = model.NumberOfRooms;
                editApartment.HaveFurnishings  = model.HaveFurnishings;
                editApartment.HaveBasement     = model.HaveBasement;
                editApartment.HaveBalcony      = model.HaveBalcony;


                if (model.MainImage != null)

                {
                    string filePath = Path.Combine(hostingEnvironment.WebRootPath,
                                                   "images", model.MainImageName);
                    System.IO.File.Delete(filePath);
                    string name = manager.ReturnUniqueName(model.MainImage);
                    manager.UploadPhoto(model.MainImage, Path.Combine(hostingEnvironment.WebRootPath,
                                                                      "images"), name);
                    editApartment.MainImage = new Photo
                    {
                        PhotoName = name,
                        PhotoPath = Path.Combine(hostingEnvironment.WebRootPath, "images")
                    };
                    editApartment.MainImageName = name;
                }
                if (model.Images != null)
                {
                    List <string> photoNames = new List <string>();

                    foreach (var image in editApartment.Images)
                    {
                        System.IO.File.Delete(image.PhotoPath);
                    }
                    foreach (var photo in model.Images)
                    {
                        string name = manager.ReturnUniqueName(photo);
                        photoNames.Add(name);
                        manager.UploadPhoto(photo, editApartment.Images.FirstOrDefault().PhotoPath, name);
                    }
                    foreach (var photoName in photoNames)
                    {
                        editApartment.Images.Add(new Photo {
                            PhotoName = photoName, PhotoPath = Path.Combine(hostingEnvironment.WebRootPath, "images")
                        });
                    }
                }

                unit.ApartmentRepository.EditApartment(editApartment);
                unit.SaveData();
                return(RedirectToAction("Success", "Customers"));
            }
            return(View(model));
        }
コード例 #4
0
        public IActionResult Edit(EditHomeViewModel model)
        {
            if (ModelState.IsValid)
            {
                var home = unit.HomeRepository.GetHome(model.Id);

                home.Name             = model.Name;
                home.Price            = model.Price;
                home.Address          = model.Address;
                home.NumberOfRooms    = model.NumberOfRooms;
                home.SquareMetrage    = model.SquareMetrage;
                home.City             = model.City;
                home.ConstructionYear = model.ConstructionYear;
                home.NumberOfFloors   = model.NumberOfFloors;
                home.Advance          = model.Advance;
                home.FullDescription  = model.Description;
                home.TotalArea        = model.TotalArea;
                home.HaveFurnishings  = model.HaveFurnishings;
                home.HaveGarage       = model.HaveGarage;

                if (model.MainImage != null)
                {
                    string filePath = Path.Combine(environment.WebRootPath,
                                                   "images", model.MainImageName);
                    System.IO.File.Delete(filePath);
                    string name = manager.ReturnUniqueName(model.MainImage);
                    manager.UploadPhoto(model.MainImage, Path.Combine(environment.WebRootPath,
                                                                      "images"), name);
                    home.MainImage = new Photo
                    {
                        PhotoName = name,
                        PhotoPath = Path.Combine(environment.WebRootPath, "images")
                    };
                    home.MainImageName = name;
                }
                if (model.Images != null)
                {
                    List <string> photoNames = new List <string>();

                    foreach (var image in home.Images)
                    {
                        System.IO.File.Delete(image.PhotoPath);
                    }
                    foreach (var photo in model.Images)
                    {
                        var name = manager.ReturnUniqueName(photo);
                        photoNames.Add(name);
                        manager.UploadPhoto(photo, home.Images.FirstOrDefault().PhotoPath, name);
                    }
                    foreach (var photoName in photoNames)
                    {
                        home.Images.Add(new Photo {
                            PhotoName = photoName, PhotoPath = Path.Combine(environment.WebRootPath, "images")
                        });
                    }
                }

                unit.HomeRepository.EditHome(home);
                unit.SaveData();
                return(RedirectToAction("Success", "Customers"));
            }

            return(View(model));
        }
コード例 #5
0
        public async Task <IActionResult> AddHome(AddHomeViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.GetUserAsync(HttpContext.User);

                Home home = new Home
                {
                    Name             = model.Name,
                    NumberOfFloors   = model.NumberOfFloors,
                    NumberOfRooms    = model.NumberOfRooms,
                    PropertyType     = PropertyType.Dom,
                    Address          = model.Address,
                    Advance          = model.Advance,
                    City             = model.City,
                    ConstructionYear = model.ConstructionYear,
                    FullDescription  = model.Description,
                    HaveFurnishings  = model.HaveFurnishings,
                    HaveGarage       = model.HaveGarage,
                    SquareMetrage    = model.SquareMetrage,
                    TotalArea        = model.TotalArea,
                    Price            = model.Price,
                    MainPageDisplay  = model.MainPageDisplay,
                    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,
                    Home         = home
                };
                string mainName;
                if (model.MainImage != null)
                {
                    mainName = adManager.ReturnUniqueName(model.MainImage);
                    var photo = new Photo()
                    {
                        PhotoName = mainName,
                        PhotoPath = Path.Combine(hostingEnvironment.WebRootPath, "images")
                                    //If using HasOne (OneToOne Relationship) instead of Owns One(OwnedType)
                                    //HomePrincipal = home
                    };
                    adManager.UploadPhoto(model.MainImage, Path.Combine(hostingEnvironment.WebRootPath, "images"), mainName);
                    home.MainImageName = photo.PhotoName;
                }
                //Lista przchowująca dane nazw zdjęć ponieważ uniqueName ma ograniczony scope
                List <string> photoNames = new List <string>();
                if (model.Images != null && model.Images.Count > 0)
                {
                    //Tworzenie Folderu na zdjęcia
                    var galleryPath = Path.Combine(hostingEnvironment.WebRootPath, "images", "Gallery_home_id_" + $"{model.Name}");
                    if (!Directory.Exists(galleryPath))
                    {
                        Directory.CreateDirectory(galleryPath);
                    }
                    foreach (var photo in model.Images)
                    {
                        string uniqueName = adManager.ReturnUniqueName(photo);
                        photoNames.Add(uniqueName);
                        adManager.UploadPhoto(photo, galleryPath, uniqueName);
                    }
                    foreach (var photoName in photoNames)
                    {
                        home.Images.Add(new Photo {
                            PhotoName = photoName, PhotoPath = galleryPath                         /*HomesPrincipal = home*/
                        });
                    }
                }
                adv.Home = home;
                unit.AdvertismentRepository.AddAdvertisement(adv);
                unit.SaveData();
                //Jeśli ogłoszenie ma być wyświetlane na stronie głównej,
                //następuje przekierowanie do metody Promote gdzie trzeba dokonać płatności za promowanie
                if (home.MainPageDisplay == true)
                {
                    return(RedirectToAction("Promote", "Advertisements", new { id = adv.AdvertisementId }));
                }
            }
            return(RedirectToAction("Success", "Customers"));
        }