// GET: Properties/Edit/5
        public ActionResult Edit(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Property property = db.Properties.Find(id);

            if (property == null)
            {
                return(HttpNotFound());
            }

            var prop = new FullProperty();

            prop.PropertyID          = property.PropertyID;
            prop.AddressDetails      = property.AddressDetails;
            prop.AllowVisitors       = property.AllowVisitors;
            prop.Area                = property.Area;
            prop.CanInstallment      = property.CanInstallment;
            prop.Comments            = property.Comments;
            prop.Commission          = property.Commission;
            prop.CommissionType      = property.CommissionType;
            prop.CustomerID          = property.CustomerID;
            prop.DownPayment         = property.DownPayment;
            prop.FloorNum            = property.FloorNum;
            prop.HasElevator         = property.HasElevator;
            prop.HasGarage           = property.HasGarage;
            prop.IsUnit              = property.IsUnit;
            prop.LocationID          = property.LocationID;
            prop.NoOfProperties      = property.NoOfProperties;
            prop.NoOfYears           = property.NoOfYears;
            prop.NumberOfBathrooms   = property.NumberOfBathrooms;
            prop.NumberOfRooms       = property.NumberOfRooms;
            prop.OwnerShipTypeID     = property.OwnerShipTypeID;
            prop.Price               = property.Price;
            prop.ProjectID           = property.ProjectID;
            prop.PropertyFloorTypeID = property.PropertyFloorTypeID;
            prop.PropertyPurposeID   = property.PropertyPurposeID;
            prop.PropertyTypeID      = property.PropertyTypeID;
            prop.ReadyDate           = property.ReadyDate;
            prop.SharedID            = property.SharedID;
            prop.Title               = property.Title;
            prop.IsActive            = true;

            ViewBag.LocationID = property.LocationID;
            ViewBag.Images     = db.Files.Where(x => x.ParentID == id && x.ParentType == "Properties").ToList();
            InitPage("Edit");
            return(View("Property", prop));
        }
        public ActionResult Create([Bind(Include = "CustomerID,LocationID,AddressDetails,ProjectID,IsUnit,Price,CanInstallment,NoOfYears,DownPayment,FloorNum,PropertyFloorTypeID,NoOfProperties,Area,OwnerShipTypeID,PropertyTypeID,PropertyPurposeID,HasElevator,HasGarage,NumberOfRooms,NumberOfBathrooms,ReadyDate,SharedID,Comments,AllowVisitors,Commission,Title,IsActive,CommissionType")] FullProperty property, HttpPostedFileBase[] files)
        {
            var modelErrors = ModelState.Where(x => x.Value.Errors.Count > 0).ToList();

            if (ModelState.IsValid)
            {
                var prop = new Property();
                prop.AddressDetails      = property.AddressDetails;
                prop.AllowVisitors       = property.AllowVisitors;
                prop.Area                = property.Area;
                prop.CanInstallment      = property.CanInstallment;
                prop.Comments            = property.Comments;
                prop.Commission          = property.Commission;
                prop.CustomerID          = property.CustomerID;
                prop.DownPayment         = property.DownPayment;
                prop.FloorNum            = property.FloorNum;
                prop.HasElevator         = property.HasElevator;
                prop.HasGarage           = property.HasGarage;
                prop.IsDeleted           = false;
                prop.IsUnit              = property.IsUnit;
                prop.LocationID          = property.LocationID;
                prop.NoOfProperties      = property.NoOfProperties;
                prop.NoOfYears           = property.NoOfYears;
                prop.NumberOfBathrooms   = property.NumberOfBathrooms;
                prop.NumberOfRooms       = property.NumberOfRooms;
                prop.OwnerShipTypeID     = property.OwnerShipTypeID;
                prop.Price               = property.Price;
                prop.ProjectID           = property.ProjectID == 0 ? null : property.ProjectID;
                prop.PropertyFloorTypeID = property.PropertyFloorTypeID;
                prop.PropertyPurposeID   = property.PropertyPurposeID;
                prop.PropertyTypeID      = property.PropertyTypeID;
                prop.ReadyDate           = property.ReadyDate;
                prop.SharedID            = property.SharedID;
                prop.Title               = property.Title;
                prop.CommissionType      = property.CommissionType;

                prop.EntryDate   = DateTime.Now;
                prop.LastUpdated = DateTime.Now;
                prop.ByUserID    = CurrentUser.UserID;
                prop.IsActive    = true;
                db.Properties.Add(prop);
                db.SaveChanges();
                AddImages(files, prop.PropertyID);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            InitPage("Create");
            return(View("Property", property));
        }