public async Task <IActionResult> Create([Bind("BuildingId,Title,City,ZipCode,BedCount,Condition,PricePerDay,HasWlan,WlanPrice,HasParking,ParkingPrice,Space,HasBalkony,UserId,IsActive")] Building building, List <Microsoft.AspNetCore.Http.IFormFile> files) { if (ModelState.IsValid) { if (files != null) { foreach (var file in files.Where(f => f.Length > 0)) { using (var stream = file.OpenReadStream()) { using (var br = new System.IO.BinaryReader(stream)) { var buildingImage = new Image(); buildingImage.Content = br.ReadBytes((int)file.Length); buildingImage.ContentType = file.ContentType; if (building.ImageList == null) { building.ImageList = new List <Image>(); } building.ImageList.Add(buildingImage); } } } } _context.Add(building); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ImageId"] = new SelectList(_context.Set <Image>(), "ImageId", "ImageId", building.ImageId); ViewData["UserId"] = new SelectList(_context.Set <User>(), "UserId", "UserId", building.UserId); return(View(building)); }
public async Task <IActionResult> Create([Bind("ImageId,Name,Description,Content,ContentType")] Image image) { if (ModelState.IsValid) { _context.Add(image); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(image)); }
public async Task <IActionResult> Create([Bind("UserId,Email,Firstname,Lastname,Password")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async Task <IActionResult> Create([Bind("RentId,BuildingTypeId,UserId,From,To,PricePerDaya,GuestWasHere")] Rent rent) { if (ModelState.IsValid) { _context.Add(rent); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["UserId"] = new SelectList(_context.User, "UserId", "UserId", rent.UserId); return(View(rent)); }