private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var apartmentVM = new ApartmentVM();

            this.DataContext = null;
            this.DataContext = apartmentVM;
        }
        public async Task <ActionResult> AddApartment(ApartmentVM apartmentvm, int buildingID)
        {
            if (ModelState.IsValid)
            {
                //if (User.Identity.IsAuthenticated)
                //{

                var apartment = new Apartment
                {
                    ApartmentNumber = apartmentvm.ApartmentNumber,
                    BuildingID      = buildingID,
                    FloorNumber     = apartmentvm.FloorNumber
                };
                db.Apartment.Add(apartment);
                await db.SaveChangesAsync();

                //======================insert Add Building Activity================
                //var UserID = User.Identity.GetUserId();// gets logged user ID
                //AspNetUsers myUser = await db.AspNetUsers.FirstOrDefaultAsync(c => c.Id == UserID);select from db where logged use match
                //var newActivity = new UserActivityLog
                //{
                //    BuildingID = BuildingID,
                //    UserID = User.Identity.GetUserId(),
                //    DateOfEvent = DateTime.Now,
                //    FunctionPerformed = "Added apartment",
                //    Message = "Apartment # " + apartmentvm.ApartmentNumber + " was added by " + myUser.UserName
                //};
                //db.UserActivityLog.Add(newActivity);
                //await db.SaveChangesAsync();
            }
            //}
            return(RedirectToAction("BuildingProfile", "Building", new { BuildingID = buildingID }));
        }
        IHttpActionResult Get()
        {
            List <ApartmentVM> apartments = new List <ApartmentVM>();
            List <Structure>   structures = db.Games.FirstOrDefault().Structures.ToList();

            if (structures == null)
            {
                return(NotFound());
            }
            for (int i = 0; i < structures.Count(); i++)
            {
                if (structures[i].IsResidence)
                {
                    ApartmentVM vm = new ApartmentVM();
                    vm.id        = structures[i].ID;
                    vm.capacity  = structures[i].SupportedPopulation;
                    vm.purchased = true;
                    vm.type      = "apartment";
                    vm.cost      = structures[i].InitialCost;
                    vm.floor     = structures[i].Floor;
                    vm.income    = structures[i].Income;
                    vm.upKeep    = structures[i].UpKeep;
                    apartments.Add(vm);
                }
            }
            return(Ok(new EmberWrapper {
                apartments = apartments
            }));
        }
        public ActionResult AddApartment(int buildingID)
        {
            var apartment = new ApartmentVM();

            apartment.BuildingID = buildingID;



            return(View(apartment));
        }
Esempio n. 5
0
        private GenricApartment <ListsVM, RentVM, SaleVM, ApartmentVM> PopulateLists(string lists, Action <Rent, Sale, Apartment> action)
        {
            ListsVM listsVm = new ListsVM()
            {
                Bedrooms    = lists.GetSelectListAsync("bedrooms", "bedroomsCount"),
                Countries   = lists.GetSelectListAsync("countries", "country").OrderBy(o => o.Text),
                Furnishings = lists.GetSelectListAsync("furnishings", "furnitureType"),
                Owners      = lists.GetSelectListAsync("owners", "fullName").OrderBy(o => o.Text)
            };
            RentVM rent = new RentVM()
            {
                Periods = lists.GetSelectListAsync("periods", "period")
            };
            SaleVM      sale      = new SaleVM();
            ApartmentVM apartment = new ApartmentVM();

            action.Invoke(rent.Rent, sale.Sale, apartment.Apartment);
            return(new GenricApartment <ListsVM, RentVM, SaleVM, ApartmentVM>(listsVm, rent, sale, apartment));
        }
Esempio n. 6
0
        public async Task <ActionResult> ApartmentProfile(int?ApartmentID, int BuildingID)
        {
            var buildinginfo = await db.Buildings
                               .Join(db.Apartment,
                                     b => b.ID,
                                     c => c.BuildingID,
                                     (b, c) => new BuildingInfoVM
            {
                ID            = c.ID,
                BuildingID    = b.ID,
                BuildingName  = b.BuildingName,
                BuildingPhone = b.BuildingPhone,
                Address       = b.Address,
                City          = b.City,
                ZipCode       = b.Zipcode,
                Manager       = b.Manager,
                NumberOfApart = (int)b.NumberOfApartment,
                States        = b.State,
                AptID         = c.ID
            })
                               .Where(cb => cb.AptID == ApartmentID)
                               .FirstAsync();

            Session["Building"] = buildinginfo;

            var apartmentinfo    = new ApartmentVM();
            var apartmentprofile = await db.Apartment
                                   .Where(a => a.ID == ApartmentID)
                                   .Select(c => new ApartmentVM
            {
                ApartmentNumber = c.ApartmentNumber,
                FloorNumber     = c.FloorNumber,
                BuildingID      = (int)c.BuildingID,
                ID = c.ID
            }).ToListAsync();

            var tenant = await db.Tenant
                         .Where(t => t.aptID == ApartmentID).ToListAsync();

            ViewBag.tenant = tenant;

            return(View(apartmentprofile));
        }