Esempio n. 1
0
        public async Task <ActionResult <User> > User()
        {
            int id   = _idsaferservice.GetUserID();
            var user = await _context.Users.SingleOrDefaultAsync(u => u.Id == id);

            if (user == null)
            {
                return(NotFound());
            }
            return(user);
        }
Esempio n. 2
0
        public async Task <ActionResult <Rental> > PostRental([FromForm] RentalViewModel rvm)
        {
            for (int i = 0; i < 10; i++)
            {
                rvm.Bookings.Add(new Booking()
                {
                    GuestName = $"Guest{i}"
                });
            }
            Rental rental = new Rental
            {
                UserID         = _idsaferservice.GetUserID(),
                Title          = rvm.Title,
                Region         = rvm.Region,
                Street         = rvm.Street,
                Rooms          = rvm.Rooms,
                Cost           = rvm.Cost,
                Floor          = rvm.Floor,
                PropertyType   = rvm.PropertyType,
                RentTime       = rvm.RentTime,
                Phone          = rvm.Phone,
                Description    = rvm.Description,
                Latitude       = rvm.Latitude,
                Longitude      = rvm.Longitude,
                Facilities     = rvm.Facilities,
                Infrastructure = rvm.Infrastructure,
                Bookings       = rvm.Bookings,
                Photos         = new List <ImageModel> {
                }
            };

            if (rvm.Photos != null)
            {
                foreach (var uploadedFile in rvm.Photos)
                {
                    ImageModel file = new ImageModel {
                        Name = uploadedFile.FileName
                    };
                    file.Path = await _cloudStorage.UploadFileAsync(uploadedFile, file.Name);

                    rental.Photos.Add(file);
                }
            }
            _context.Rental.Add(rental);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetRental", new { id = rental.RentalID }, rental));
        }