public Task ToHomeAsync(AddHomeViewModel model, bool v) { throw new NotImplementedException(); }
public async Task <IActionResult> AddObject(AddHomeViewModel mode, IFormFileCollection files) { Home home = new Home { About = mode.About, Adress = mode.Adress, TypeSdelki = mode.TypeSdelki, Coords = mode.Coords, AllCountRoom = mode.AllCountRoom, AllPloshadRoom = mode.AllPloshadRoom, Animals = mode.Animals, Balkon = mode.Balkon, Children = mode.Children, Communal = mode.Communal, Comnat = mode.Comnat, Etag = mode.Etag, EtagAll = mode.EtagAll, Kuxnya = mode.Kuxnya, ObjectText = mode.ObjectText, Name = mode.Name, Price = mode.Price, PloshadRoom = mode.PloshadRoom, Predoplata = mode.Predoplata, Sostav = mode.Sostav, Parkovka = mode.Parkovka, Remont = mode.Remont, SanUzelRazdel = mode.SanUzelRazdel, SanUzelVmeste = mode.SanUzelVmeste, TypeArenda = mode.TypeArenda, TypeCommerce = mode.TypeCommerce, Zalog = mode.Zalog }; var result = await _context.AddAsync(home); if (mode.Dop != null) { foreach (string text in mode.Dop) { await _context.AddAsync(new Dop { HomeId = result.Entity.Id, Text = text }); } } if (files.Count() != 0) { foreach (var uploadedFile in files) { Photos photos = new Photos(); using (var memoryStream = new MemoryStream()) { await uploadedFile.CopyToAsync(memoryStream); photos.Photo = memoryStream.ToArray(); } photos.HomeId = result.Entity.Id; await _context.AddAsync(photos); } } await _context.AddAsync(home); await _context.SaveChangesAsync(); return(RedirectToAction("Panel", "Admin")); }
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")); }