public bool GetHighestUniqueBid() { Bid = null; try { RealEntities db = new RealEntities(); var bids = db.bids.Where(b => b.property_id == PropertyId).GroupBy(b => (b.bid_price.plot_price + b.bid_price.apartment_price)).Where(b => (b.Count() == 1)).FirstOrDefault(); if (null == bids) { return(false); } var bid = bids.FirstOrDefault(); if (null == bid) { return(false); } Bid = new BidVieModel(); Bid.BidId = bid.bid_id; Bid.PropertyId = bid.property_id; Bid.BuyerId = bid.buyer_id; Bid.Status = ( BidStatus )bid.status; Bid.LandPrice = ( double )bid.bid_price.plot_price; Bid.HousePrice = ( double )bid.bid_price.apartment_price; Bid.BuyerName = bid.buyer.user.first_name + " " + bid.buyer.user.last_name; Bid.BuyerAddress = bid.buyer.user.address; return(true); } catch (Exception ex) { } return(false); }
public bool ConfirmBid() { try { RealEntities db = new RealEntities(); var bids = db.bids.Where(b => b.property_id == PropertyId && b.bid_id != BidId); if (null != bids) { foreach (var b in bids) { b.status = ( int )BidStatus.Rejected; } } var bid = db.bids.Where(b => b.bid_id == BidId).FirstOrDefault(); if (null != bid) { bid.status = ( int )BidStatus.Approved; } db.SaveChanges(); return(true); } catch (Exception ex) { } return(false); }
public void GetProperties() { if (null != Properties) { Properties.Clear(); } using (RealEntities db = new RealEntities()) { buyer buyer = db.buyers.Where(b => b.buyer_id == BuyerId).FirstOrDefault(); List <property> properties = null; if (buyer != null) { properties = db.properties.Where(p => p.area <= buyer.max_area && p.area >= buyer.min_area && (p.min_price.plot_price + p.min_price.apartment_price) <= buyer.max_cost && (p.min_price.plot_price + p.min_price.apartment_price) >= buyer.min_cost).ToList <property>(); } if (null == Properties) { Properties = new List <PropertyViewModel>(); } if (null != properties) { foreach (var property in properties) { PropertyViewModel pm = new PropertyViewModel(property); Properties.Add(pm); } } } }
public PropertyViewModel(int PropertyId) { RealEntities db = new RealEntities(); property prop = db.properties.Where(p => p.property_id == PropertyId).FirstOrDefault(); InitialiseProperty(prop); }
public bool UserLogin() { try { RealEntities db = new RealEntities(); user user = db.users.Where(u => u.user_name == UserName && u.password == Password).FirstOrDefault(); if (null == user) { return(false); } UserId = user.user_id; seller seller = db.sellers.Where(s => s.user_id == user.user_id).FirstOrDefault(); buyer buyer = db.buyers.Where(b => b.user_id == user.user_id).FirstOrDefault(); if (null != buyer && null != seller) { Type = UserType.Both; } else if (null != buyer) { Type = UserType.Buyer; } else if (null != seller) { Type = UserType.Seller; } return(true); } catch (Exception ex) { } return(false); }
public static Dictionary <int, string> GetCategories() { if (null != _categories) { return(_categories); } using (RealEntities db = new RealEntities()) { _categories = db.categories.ToDictionary(c => c.category_id, c => c.type); } return(_categories); }
public bool ChangeStatus(PropertyStatus status) { try { RealEntities db = new RealEntities(); property prop = db.properties.Where(p => p.property_id == PropertyId).FirstOrDefault(); prop.status = ( int )status; db.SaveChanges(); return(true); } catch (Exception ex) { } return(false); }
public static int GetBuyer() { int buyerid = 0; Object user = System.Web.HttpContext.Current.Session["UserId"]; if (null != user) { long userid = (long)user; using (RealEntities db = new RealEntities()) { buyer buyer = db.buyers.Where(b => b.user_id == userid).FirstOrDefault(); buyerid = buyer.buyer_id; } } return(buyerid); }
public static int GetSeller() { int sellerid = 0; Object user = System.Web.HttpContext.Current.Session["UserId"]; if (null != user) { long userid = (long)user; using (RealEntities db = new RealEntities()) { seller seller = db.sellers.Where(s => s.user_id == userid).FirstOrDefault(); sellerid = seller.seller_id; } } return(sellerid); }
public BidVieModel(int bidId) { RealEntities db = new RealEntities(); var bid = db.bids.Where(b => b.bid_id == bidId).FirstOrDefault(); if (null != bid) { BidId = bid.bid_id; PropertyId = bid.property_id; BuyerId = bid.buyer_id; Status = ( BidStatus )bid.status; LandPrice = ( double )bid.bid_price.plot_price; HousePrice = ( double )bid.bid_price.apartment_price; BuyerName = bid.buyer.user.first_name + " " + bid.buyer.user.last_name; BuyerAddress = bid.buyer.user.address; } }
public void GetProperties() { if (null != Properties) { Properties.Clear(); } else { Properties = new List <PropertyViewModel>(); } using (RealEntities db = new RealEntities()) { var properties = db.properties.Where(p => p.seller_id == SellerId).ToList <property>(); if (null != properties) { foreach (var property in properties) { PropertyViewModel pm = new PropertyViewModel(property); Properties.Add(pm); } } } }
public bool GetBids() { if (null != Bids) { Bids.Clear(); } else { Bids = new List <BidVieModel>(); } try { RealEntities db = new RealEntities(); var bids = db.bids.Where(b => b.property_id == PropertyId); if (null != bids) { foreach (var b in bids) { BidVieModel bid = new BidVieModel(); bid.BidId = b.bid_id; bid.PropertyId = b.property_id; bid.BuyerId = b.buyer_id; bid.Status = ( BidStatus )b.status; //bid.LandPrice = ( double )b.bid_price.plot_price; //bid.HousePrice = ( double )b.bid_price.apartment_price; //bid.BuyerName = b.buyer.user.first_name + " " + b.buyer.user.last_name; //bid.BuyerAddress = b.buyer.user.address; Bids.Add(bid); } } return(true); } catch (Exception ex) { } return(false); }
internal bool Place() { try { RealEntities db = new RealEntities(); bid bid = new bid(); bid.property_id = PropertyId; bid.buyer_id = BuyerId; bid.status = ( int )Status; db.bids.Add(bid); db.SaveChanges(); bid_price bp = new bid_price(); bp.bid_id = bid.bid_id; bp.apartment_price = HousePrice; bp.plot_price = LandPrice; db.bid_price.Add(bp); db.SaveChanges(); return(true); } catch (Exception ex) { } return(false); }
private List <Marker> GetMarkers() { using (RealEntities db = new RealEntities()) { List <Marker> markers = new List <Marker>(); if (null != church) { foreach (var marker in JsonConvert.DeserializeObject <List <Marker> >(church)) { landmarktype lt = db.landmarktypes.Where(t => t.type_name == "Church").FirstOrDefault(); if (null == lt) { continue; } marker.Type = lt.type_id; markers.Add(marker); } } if (null != school) { foreach (var marker in JsonConvert.DeserializeObject <List <Marker> >(school)) { landmarktype lt = db.landmarktypes.Where(t => t.type_name == "School").FirstOrDefault(); if (null == lt) { continue; } marker.Type = lt.type_id; markers.Add(marker); } } if (null != train_station) { foreach (var marker in JsonConvert.DeserializeObject <List <Marker> >(train_station)) { landmarktype lt = db.landmarktypes.Where(t => t.type_name == "Railway").FirstOrDefault(); if (null == lt) { continue; } marker.Type = lt.type_id; markers.Add(marker); } } if (null != hindu_temple) { foreach (var marker in JsonConvert.DeserializeObject <List <Marker> >(hindu_temple)) { landmarktype lt = db.landmarktypes.Where(t => t.type_name == "Temple").FirstOrDefault(); if (null == lt) { continue; } marker.Type = lt.type_id; markers.Add(marker); } } if (null != hospital) { foreach (var marker in JsonConvert.DeserializeObject <List <Marker> >(hospital)) { landmarktype lt = db.landmarktypes.Where(t => t.type_name == "Hospital").FirstOrDefault(); if (null == lt) { continue; } marker.Type = lt.type_id; markers.Add(marker); } } if (null != mosque) { foreach (var marker in JsonConvert.DeserializeObject <List <Marker> >(mosque)) { landmarktype lt = db.landmarktypes.Where(t => t.type_name == "Mosque").FirstOrDefault(); if (null == lt) { continue; } marker.Type = lt.type_id; markers.Add(marker); } } return(markers); } }
public bool AddProperty() { try { property prop = new property(); List <Marker> markers = GetMarkers(); RealEntities db = new RealEntities(); prop.name = Name; prop.area = Area; prop.latitude = Latitude; prop.longitude = Longitude; prop.seller_id = SellerId; prop.category = Category; prop.status = 1; db.properties.Add(prop); db.SaveChanges(); min_price price = new min_price(); switch (prop.category) { case 1: { price.plot_price = LandPrice; price.apartment_price = 0; break; } case 2: { price.plot_price = LandPrice; price.apartment_price = HousePrice; break; } case 3: { price.plot_price = 0; price.apartment_price = HousePrice; break; } } price.property_id = prop.property_id; db.min_price.Add(price); db.SaveChanges(); db.properties.Attach(prop); foreach (var marker in markers) { RealEntities ldb = new RealEntities(); landmark lm = ldb.landmarks.Where(l => l.latitude == marker.Lat && l.longitude == marker.Lng && l.landmarktype == marker.Type).FirstOrDefault(); if (null == lm) { lm = new landmark(); lm.landmarktype = marker.Type; lm.latitude = marker.Lat; lm.longitude = marker.Lng; lm.name = marker.Name; ldb.landmarks.Add(lm); ldb.SaveChanges(); } if (0 != lm.landmark_id) { landmark mark = db.landmarks.Where(l => l.landmark_id == lm.landmark_id).Single(); db.landmarks.Attach(mark); prop.landmarks.Add(mark); } } db.SaveChanges(); foreach (HttpPostedFileBase image in Images) { //Checking file is available to save. if (image != null) { image img = new image(); img.property_id = prop.property_id; MemoryStream target = new MemoryStream(); image.InputStream.CopyTo(target); img.image1 = target.ToArray(); db.images.Add(img); } } db.SaveChanges(); return(true); } catch (Exception ex) { } return(false); }
public bool RegisterUser() { try { RealEntities db = new RealEntities(); user u = new user(); u.user_name = UserName; u.password = Password; u.first_name = FirstName; u.last_name = LastName; u.address = Address; u.pan_no = PAN; u.mob_no = Mob; u.email = Email; u.status_id = 1; db.users.Add(u); db.SaveChanges(); UserId = u.user_id; switch (Type) { case UserType.Buyer: { buyer b = new buyer(); b.user_id = u.user_id; b.max_area = MaxArea; b.min_area = MinArea; b.min_cost = MinCost; b.max_cost = MaxCost; db.buyers.Add(b); break; } case UserType.Both: { buyer b = new buyer(); b.user_id = u.user_id; b.max_area = MaxArea; b.min_area = MinArea; b.min_cost = MinCost; b.max_cost = MaxCost; db.buyers.Add(b); seller s = new seller(); s.seller_type = 2; s.user_id = u.user_id; db.sellers.Add(s); break; } case UserType.Seller: { seller s = new seller(); s.seller_type = 1; s.user_id = u.user_id; db.sellers.Add(s); break; } } db.SaveChanges(); return(true); } catch (Exception ex) { } return(false); }