public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            _viewModel = ViewModelProviders.Of(this).Get(DependencyLocator.Current.CreateHousesViewModel);
            _viewModel.ViewDidLoad();
        }
        // GET: Houses/Edit/5
        //[Authorize(Roles = RoleName.CanManageHouses)]
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            //House house = db.Houses.Find(id);
            //if (house == null)
            //{
            //    return HttpNotFound();
            //}
            //var allFeatures = db.Features.ToList();
            var housesViewModel = new HousesViewModel();

            {
                housesViewModel.House = db.Houses.Include(i => i.Features).SingleOrDefault(i => i.Id == id);
                //HousesViewModel.Features = allFeatures.ToList();
            }
            if (housesViewModel.House == null)
            {
                return(HttpNotFound());
            }

            var allFeaturesList = db.Features.ToList();

            ViewBag.AllFeatures = allFeaturesList.Select(o => new SelectListItem
            {
                Text  = o.Feature.ToString(),
                Value = o.Id.ToString()
            });

            ViewBag.RegionId = new SelectList(db.Regions, "RegionId", "RegionName");

            return(View(housesViewModel));
        }
Exemplo n.º 3
0
        public ActionResult Edit(HousesViewModel housesViewModel)
        {
            if (ModelState.IsValid)
            {
                var houseToAdd = housesViewModel;
                if (TryUpdateModel(houseToAdd, "house", new string[] { "Features", "RegionId" }))
                {
                    var updatedFeatures = new HashSet <byte>(housesViewModel.SelectedFeatures);
                    //var updatedRegion = housesViewModel.SelectedRegion;

                    foreach (Features features in db.Features)
                    {
                        if (!updatedFeatures.Contains(features.Id))
                        {
                            houseToAdd.House.Features.Remove(features);
                        }
                        else
                        {
                            houseToAdd.House.Features.Add((features));
                        }
                    }
                }
                db.Entry(houseToAdd.House).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            //ViewBag.Id = new SelectList(db.Houses, "Id", "Title", housesViewModel.House.Id);
            ViewBag.RegionId = new SelectList(db.Regions, "RegionId", "RegionName");

            return(View(housesViewModel));
        }
Exemplo n.º 4
0
        public App()
        {
            InitializeComponent();

            TilesDB tiledb = new TilesDB();


            housesViewModel = new HousesViewModel();

            MainPage = new MainPage();

            // sort out houses database
            string sqliteFilename = "houses.db";
            string dbPath         = Path.Combine(GetDatabasePath(), sqliteFilename);

            if (App.RebuildDB)
            {
                File.Delete(dbPath);
            }
            // Check if your DB has already been created.
            if (!File.Exists(dbPath))
            {
                Task t = housesViewModel.GetHousesAsync();
            }
            else
            {
                housesDB = new SQLiteConnection(dbPath);
                String query = "SELECT * FROM House";
                houses = App.housesDB.Query <House>(query);
            }
        }
        public ActionResult Houses(HouseFilterCriteria filter, AnnouncementType type = AnnouncementType.Buy, AnnouncementOrder order = AnnouncementOrder.Address, NavigationViewType viewtype = NavigationViewType.List, int page = 1, bool considerEmpty = true)
        {
            IEnumerable <HouseAnnouncement> houses = _announcementRepository.GetListOfHouses().ToList().Where(an => an.Type == type && an.Address.HasValue);

            switch (order)
            {
            case AnnouncementOrder.Address: houses = houses.OrderBy(a => a.Address.ToString()); break;

            case AnnouncementOrder.AddressDescending: houses = houses.OrderByDescending(a => a.Address.ToString()); break;

            case AnnouncementOrder.Date: houses = houses.OrderBy(a => a.Created); break;

            case AnnouncementOrder.DateDescending: houses = houses.OrderByDescending(a => a.Created); break;

            default: houses = houses.OrderBy(a => a.Address.ToString()); break;
            }

            if (ModelState.IsValid)
            {
                if (filter != null)
                {
                    if (filter.IsEmpty() && considerEmpty)
                    {
                        HouseFilterCriteria newFilter = ObjectToCookie.GetObjectFromCookies <HouseFilterCriteria>(Request.Cookies, COOKIE_KEY_HOUSEFILTER);
                        if (newFilter != null)
                        {
                            filter = newFilter;
                        }
                    }
                    houses = filter.Filter(houses);
                    ObjectToCookie.SetCookieAsObject <HouseFilterCriteria>(filter, Response.Cookies, COOKIE_KEY_HOUSEFILTER);
                }
            }
            else
            {
                filter = new HouseFilterCriteria();
            }


            ViewBag.ViewType  = viewtype;
            ViewBag.Type      = type;
            ViewBag.OrderType = order;

            if (viewtype == NavigationViewType.List)
            {
                HousesListViewModel viewModel = new HousesListViewModel();
                viewModel.Page = createPageInfo(page, houses.Count());
                setViewModel(viewModel, announcementsForPage(houses, page));
                viewModel.FilterCriteria = filter;
                return(View("Houses", viewModel));
            }
            else
            {
                HousesViewModel viewModel = new HousesViewModel();
                setViewModel(viewModel, houses);
                viewModel.FilterCriteria = filter;
                return(View("HousesMap", viewModel));
            }
        }
Exemplo n.º 6
0
        public ActionResult UploadImages(HousesViewModel housesViewModel)
        {
            HttpPostedFileBase file = Request.Files["ImageData"];

            UploadImageInDataBase(file, housesViewModel);

            return(RedirectToAction("Index"));;
        }
Exemplo n.º 7
0
 private void First_Click(object sender, RoutedEventArgs e)
 {
     if (HousesViewModel.Buttons.First == null)
     {
     }
     else
     {
         HousesViewModel.LoadPage(HousesViewModel.Buttons.First);
     }
 }
Exemplo n.º 8
0
 private void Prev_Click(object sender, RoutedEventArgs e)
 {
     if (HousesViewModel.Buttons.Prev == null)
     {
     }
     else
     {
         HousesViewModel.LoadPage(HousesViewModel.Buttons.Prev);
     }
 }
        public ActionResult Create(HousesViewModel housesViewModel)
        {
            var userId = User.Identity.GetUserId();
            var user   = db.Users.Where(i => i.Id == userId).FirstOrDefault();

            housesViewModel.Owner = user;
            var allowedExtensions = new[]
            {
                ".png", ".jpg", ".jpeg"
            };


            if (ModelState.IsValid)
            {
                var houseToAdd = housesViewModel;

                if (TryUpdateModel(houseToAdd, "house", new string[] { "Id", "Features", "RegionId" }))
                {
                    var updatedFeatures = new HashSet <byte>(housesViewModel.SelectedFeatures);

                    foreach (Features features in db.Features)
                    {
                        if (!updatedFeatures.Contains(features.Id))
                        {
                            houseToAdd.House.Features.Remove(features);
                        }
                        else
                        {
                            houseToAdd.House.Features.Add((features));
                        }
                    }
                }

                //houseToAdd.House.ImageName = file.ToString();
                var fileName = Path.GetFileName(houseToAdd.House.ImageData.FileName);
                var ext      = Path.GetExtension(houseToAdd.House.ImageData.FileName);
                if (allowedExtensions.Contains(ext))
                {
                    string name   = Path.GetFileNameWithoutExtension(fileName);
                    string myfile = Guid.NewGuid() + ext;
                    var    path   = Path.Combine(Server.MapPath("/HouseImages") + "/", myfile);
                    houseToAdd.House.ImageName = myfile;
                    houseToAdd.House.ImageData.SaveAs(path);
                }
                houseToAdd.House.OwnerId = userId;

                db.Houses.Add(houseToAdd.House);
                db.SaveChanges();
                return(RedirectToAction("MyHouses", new { message = "Success" }));
                //return RedirectToAction("UploadImages");
            }

            ViewBag.RegionId = new SelectList(db.Regions, "RegionId", "RegionName");
            return(View(housesViewModel));
        }
Exemplo n.º 10
0
        private void Filter_Click(object sender, RoutedEventArgs e)
        {
            Grid parentGrid   = (Grid)((Button)sender).Parent;
            int  wordsState   = ((ComboBox)parentGrid.FindName("WordsCombo")).SelectedIndex;
            int  titlesState  = ((ComboBox)parentGrid.FindName("TitlesCombo")).SelectedIndex;
            int  seatsState   = ((ComboBox)parentGrid.FindName("SeatsCombo")).SelectedIndex;
            int  diedState    = ((ComboBox)parentGrid.FindName("DiedOutCombo")).SelectedIndex;
            int  weaponsState = ((ComboBox)parentGrid.FindName("WeaponsCombo")).SelectedIndex;

            HousesViewModel.LoadFilteredPage(wordsState, titlesState, seatsState, diedState, weaponsState);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            _viewModel = DependencyLocator.Current.CreateHousesViewModel();
            _viewModel.ViewDidLoad();

            var source = new ObservingPlainTableViewSource <HouseCellViewModel>(_viewModel.Houses, BindHouseTableViewCell, nameof(HouseTableViewCell));

            source.WillDisplayCellDelegate = WillDisplayCell;
            TableView.Source = source;
            SetBindings();
        }
Exemplo n.º 12
0
        public ActionResult Create()
        {
            var housesViewModel = new HousesViewModel();
            var allFeaturesList = db.Features.ToList();
            var currentUserId   = User.Identity.GetUserId();

            ViewBag.AllFeatures = allFeaturesList.Select(o => new SelectListItem
            {
                Text  = o.Feature.ToString(),
                Value = o.Id.ToString()
            });
            ViewBag.RegionId = new SelectList(db.Regions, "RegionId", "RegionName");
            ViewBag.OwnerId  = currentUserId;
            return(View());
        }
Exemplo n.º 13
0
        //[Authorize(Roles = RoleName.CanManageHouses)]
        public ActionResult Edit(HousesViewModel housesViewModel)
        {
            var allowedExtensions = new[] {
                ".png", ".jpg", ".jpeg"
            };

            if (ModelState.IsValid)
            {
                var houseToAdd = housesViewModel;

                if (TryUpdateModel(houseToAdd, "house", new string[] { "Features", "RegionId", "StartDate", "EndDate" }))
                {
                    var updatedFeatures = new HashSet <byte>(housesViewModel.SelectedFeatures);

                    //var updatedRegion = housesViewModel.SelectedRegion;
                    foreach (Features features in db.Features)
                    {
                        if (!updatedFeatures.Contains(features.Id))
                        {
                            houseToAdd.House.Features.Remove(features);
                        }
                        else
                        {
                            houseToAdd.House.Features.Add((features));
                        }
                    }
                    var fileName = Path.GetFileName(houseToAdd.House.ImageData.FileName);
                    var ext      = Path.GetExtension(houseToAdd.House.ImageData.FileName);
                    if (allowedExtensions.Contains(ext))
                    {
                        string name   = Path.GetFileNameWithoutExtension(fileName);
                        string myfile = Guid.NewGuid() + ext;
                        var    path   = Path.Combine(Server.MapPath("/HouseImages") + "/", myfile);
                        houseToAdd.House.ImageName = myfile;
                        houseToAdd.House.ImageData.SaveAs(path);
                    }
                    db.Entry(houseToAdd.House).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("MyHouses", new { message = "Success" }));
                }
            }
            //ViewBag.Id = new SelectList(db.Houses, "Id", "Title", housesViewModel.House.Id);
            ViewBag.RegionId = new SelectList(db.Regions, "RegionId", "RegionName");

            return(View(housesViewModel));
        }
Exemplo n.º 14
0
        public int UploadImageInDataBase(HttpPostedFileBase image, HousesViewModel housesViewModel)
        {
            housesViewModel.Image = ConvertToBytes(image);
            var imageToAdd = housesViewModel.Images;

            db.Images.Add(imageToAdd);

            int i = db.SaveChanges();

            if (i == 1)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
Exemplo n.º 15
0
        // GET: Houses/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var HousesViewModel = new HousesViewModel();

            {
                HousesViewModel.House = db.Houses.Include(i => i.Features).Include(j => j.Owner).First(i => i.Id == id);
            }

            if (HousesViewModel.House == null)
            {
                return(HttpNotFound());
            }
            //var allFeaturesList = HousesViewModel.House.Features.ToList();


            return(View(HousesViewModel));
        }
Exemplo n.º 16
0
 public HousesView(HousesViewModel viewModel = null)
 {
     InitializeComponent();
     BindingContext = viewModel;
 }
Exemplo n.º 17
0
        public HousesPage()
        {
            InitializeComponent();

            BindingContext = viewModel = new HousesViewModel();
        }
Exemplo n.º 18
0
        public ActionResult Create(HousesViewModel housesViewModel)
        //public ActionResult Create(HousesViewModel housesViewModel, Images images)
        {
            if (ModelState.IsValid)
            {
                //var houseToAdd = db.Houses
                //.Include(i => i.Features)
                //.First();
                var houseToAdd = housesViewModel;
                //var houseToAdd = new House();

                /*if (db.Houses is null)
                 * {
                 *  houseToAdd.Availability = DateTime.Now;
                 *  db.Houses.Add(houseToAdd);
                 * }*/


                if (TryUpdateModel(houseToAdd, "house", new string[] { "Id", "Features", "RegionId" }))
                {
                    var updatedFeatures = new HashSet <byte>(housesViewModel.SelectedFeatures);
                    //var updatedImages = new List<HttpPostedFileBase>();

                    foreach (Features features in db.Features)
                    {
                        if (!updatedFeatures.Contains(features.Id))
                        {
                            houseToAdd.House.Features.Remove(features);
                        }
                        else
                        {
                            houseToAdd.House.Features.Add((features));
                        }
                    }


                    //foreach (HttpPostedFileBase image in housesViewModel.Images)
                    //{
                    //    //Checking file is available to save.
                    //    if (image != null)
                    //    {
                    //        var InputFileName = Path.GetFileName(image.FileName);
                    //        var ServerSavePath = Path.Combine(Server.MapPath("/HouseImages") + InputFileName);
                    //        //Save file to server folder
                    //        image.SaveAs(ServerSavePath);
                    //        //assigning file uploaded status to ViewBag for showing message to user.
                    //        ViewBag.UploadStatus = housesViewModel.Images.Count().ToString() + " files uploaded successfully.";
                    //    }
                    //}
                }
                db.Houses.Add(houseToAdd.House);
                db.SaveChanges();

                //List<Images> images = new List<Images>();
                //for (int i = 0; i < Request.Files.Count; i++)
                //{
                //    var imageFile = Request.Files[i];
                //    if (imageFile != null && imageFile.ContentLength > 0)
                //    {
                //        var imageName = Path.GetFileName(imageFile.FileName);
                //        Images image = new Images()
                //        {
                //            ImageName = imageName,
                //            Extension = Path.GetExtension(imageName),
                //            Id = Guid.NewGuid()
                //        };

                //        images.Add(image);
                //        var path = Path.Combine(Server.MapPath("/HouseImages"), image.Id + image.Extension);
                //        imageFile.SaveAs(path);
                //    }
                //}
                //db.Houses.Add(houseToAdd.House);
                //db.SaveChanges();


                return(RedirectToAction("UploadImages"));
            }

            ViewBag.RegionId = new SelectList(db.Regions, "RegionId", "RegionName");
            //ViewBag.Images.Id = new SelectList(db.Images, "Id", "ImageName");
            return(View(housesViewModel));
        }
Exemplo n.º 19
0
 public Houses()
 {
     InitializeComponent();
     DataContext = new HousesViewModel();
 }
Exemplo n.º 20
0
        private void HouseList_OnItemClick(object sender, ItemClickEventArgs e)
        {
            var house = (House)e.ClickedItem;

            HousesViewModel.NavigateToHouseDetails(house.Url);
        }