public async Task <IActionResult> Create([Bind("BuildingId,Title,City,ZipCode,BedCount,Condition,PricePerDay,HasWlan,WlanPrice,HasParking,ParkingPrice,Space,HasBalkony,IsActive,BuildingTypeId,UserId")] 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["BuildingTypeId"] = new SelectList(_context.Set <BuildingType>(), "BuildingTypeId", "BuildingTypeId", building.BuildingTypeId);
            ViewData["UserId"]         = new SelectList(_context.User, "UserId", "UserId", building.UserId);
            return(View(building));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("RentId,BuildingId,UserId,From,To,PricePerDays,GuestWasHere")] Rent rent)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rent);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BuildingId"] = new SelectList(_context.Building, "BuildingId", "BuildingId", rent.BuildingId);
            ViewData["UserId"]     = new SelectList(_context.User, "UserId", "UserId", rent.UserId);
            return(View(rent));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("UserId,Email,Firstname,Lastname,Password")] User user)
        {
            // It is only possible to create costumers. Creating admin users is only possible with a directly sql statement
            user.UserTypeId = 2;
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserTypeId"] = new SelectList(_context.Set <UserType>(), "UserTypeId", "UserTypeId", user.UserType.Type);
            return(View(user));
        }