Example #1
0
        public async Task <IActionResult> Create(AppartmentViewModel appartment)
        {
            if (appartment.Photo != null)
            {
                BlobContainerClient containerClient = _blobService.GetBlobContainerClient("home");
                Stream          stream      = appartment.Photo.OpenReadStream();
                string          fileName    = $"{Guid.NewGuid().ToString()}{appartment.Photo.FileName}";
                BlobContentInfo blobContent = await containerClient.UploadBlobAsync(fileName, stream);

                BlobClient blobClient = containerClient.GetBlobClient(fileName);
                string     url        = blobClient.Uri.AbsoluteUri;
                Appartment newAppart  = new Appartment();
                newAppart.Title       = appartment.Title;
                newAppart.Description = appartment.Description;
                newAppart.Owner       = appartment.Owner;
                newAppart.Price       = appartment.Price;
                newAppart.Photo       = fileName;
                newAppart.PhotoPath   = url;
                _context.Add(newAppart);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(appartment));
        }
Example #2
0
        public IActionResult Index()
        {
            // some information is hardcoded until mechanisms are implemented

            MonthlyExpensesViewModel output = new MonthlyExpensesViewModel();

            output.Month    = "AUGUST";
            output.Year     = 2020;
            output.Building = _repository.GetBuildingById(2);

            List <Announcement>      allAnnouncements        = _repository.GetAllAnnouncementsByBuildingId(2);
            List <AnnouncementModel> allAnnouncementsForView = new List <AnnouncementModel>();

            foreach (var announcement in allAnnouncements)
            {
                allAnnouncementsForView.Add(new AnnouncementModel
                {
                    Id          = announcement.Id,
                    Message     = announcement.Message,
                    BuilidingId = announcement.BuilidingId,
                    DateAdded   = announcement.DateAdded
                });
            }
            output.Announcements = allAnnouncementsForView;

            List <Appartment>          allAppartments = _repository.GetAllAppartments().ToList();
            List <AppartmentViewModel> allAppartmentsIncludingOwnerNames = new List <AppartmentViewModel>();

            foreach (var appt in allAppartments)
            {
                string firstName             = _repository.GetAppartmentOwnerFirstNameById(appt.AppartmentOwnerId);
                string lastName              = _repository.GetAppartmentOwnerLastNameById(appt.AppartmentOwnerId);
                AppartmentViewModel tempAppt = new AppartmentViewModel
                {
                    Id = appt.Id,
                    AppartmentOwnerId        = appt.AppartmentOwnerId,
                    BuildingId               = appt.BuildingId,
                    Number                   = appt.Number,
                    NumberOfInhabitants      = appt.NumberOfInhabitants,
                    AppartmentOwnerFirstName = firstName,
                    AppartmentOwnerLastName  = lastName
                };
                allAppartmentsIncludingOwnerNames.Add(tempAppt);
            }
            output.Appartments = allAppartmentsIncludingOwnerNames;

            List <Bill> allBills = _repository.GetAllBillsByBuildingId(2);

            output.Bills = allBills;
            foreach (var appt in allAppartments)
            {
                output.TotalInhabitants += appt.NumberOfInhabitants;
            }
            return(View(output));
        }