Example #1
0
        /// <summary>
        /// checks to see if this plane can be rented
        /// </summary>
        /// <returns></returns>
        public bool IsRentable()
        {
            //TODO: Complete full implementation
            //check for both rental amounts, make sure its not already rented,
            //make sure its not broke (if broke can we repair it?)

            bool result = false;

            double rentalPrice = 0.0;

            if (!double.TryParse(RentalDry, out rentalPrice))
            {
                //error occured while parsing
                //TODO: handle parse error
            }

            if (rentalPrice != 0.0)
            {
                //its rentable
                if (RentedBy.CompareTo("Not rented.") == 0)
                {
                    if (int.Parse(NeedsRepair) == 0)
                    {
                        result = true;
                    }
                }
            }
            return(result);
        }
 public ActionResult Edit([Bind(Include = "Id,HouseRepresentative,FlatId,EntryDate,LeavingDate")] RentedBy rentedBy)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rentedBy).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.FlatId = new SelectList(db.Flats, "Id", "Description", rentedBy.FlatId);
     return(View(rentedBy));
 }
        // GET: RentedBies/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RentedBy rentedBy = db.RentedBys.Find(id);

            if (rentedBy == null)
            {
                return(HttpNotFound());
            }
            return(View(rentedBy));
        }
        public ActionResult LeaveRenterPdf(RentedBy rentedByForModify)
        {
            var      rentedBys = db.RentedBys.Include(a => a.Flats.Homes.HouseOwners).ToList();
            var      HR        = db.HouseRepresentatives.ToList();
            RentedBy rentedBy  = rentedBys.Find(a => a.Id == rentedByForModify.Id);

            rentedBy.HouseRepresentatives = HR.Find(a => a.Id == rentedBy.HouseRepresentative);

            ViewBag.FlatNo     = rentedBy.Flats.FlatNo.ToString();
            ViewBag.Home       = rentedBy.Flats.Homes.Name;
            ViewBag.HR         = rentedBy.HouseRepresentatives.Name;
            ViewBag.HouseOwner = rentedBy.Flats.Homes.HouseOwners.Name;
            return(View(rentedBy));
        }
        // POST: RentedBies/Delete/5
        public ActionResult DeleteConfirmed(int id)
        {
            RentedBy rentedByForModify = db.RentedBys.Find(id);

            rentedByForModify.LeavingDate     = DateTime.Now;
            db.Entry(rentedByForModify).State = EntityState.Modified;
            db.SaveChanges();


            return(new ActionAsPdf("LeaveRenterPdf", rentedByForModify)
            {
                FileName = "Leave.pdf"
            });
        }
        // GET: RentedBies/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RentedBy rentedBy = db.RentedBys.Find(id);

            if (rentedBy == null)
            {
                return(HttpNotFound());
            }
            ViewBag.FlatId = new SelectList(db.Flats, "Id", "Description", rentedBy.FlatId);
            return(View(rentedBy));
        }
        // GET: RentedBies/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var      rentedBys = db.RentedBys.Include(a => a.Flats).Include(a => a.Flats.Homes).ToList();
            var      HR        = db.HouseRepresentatives.ToList();
            RentedBy rentedBy  = rentedBys.Find(a => a.Id == id);

            rentedBy.HouseRepresentatives = HR.Find(a => a.Id == rentedBy.HouseRepresentative);
            if (rentedBy == null)
            {
                return(HttpNotFound());
            }
            return(View(rentedBy));
        }
        public ActionResult RentInfoPdf(RentedBy rentedBy1)
        {
            var rentedBys = db.RentedBys.Include(a => a.Flats.Homes.HouseOwners).ToList();
            var rentedBy  = rentedBys.Find(a => a.Id == rentedBy1.Id);

            var representatives = db.HouseRepresentatives.ToList();
            var representative  = representatives.Find(a => a.Id == rentedBy.HouseRepresentative);

            ViewBag.HR   = representative.Name;
            ViewBag.HRNo = representative.MobileNo;
            var flatMember = db.FlatMembers.Where(a => a.HouseRepresentativeId == representative.Id && a.LeavingDate == null).ToList();

            ViewBag.HouseName = rentedBy.Flats.Homes.Name;
            ViewBag.FlatNo    = rentedBy.Flats.FlatNo;
            ViewBag.Owner     = rentedBy.Flats.Homes.HouseOwners.Name;
            return(View(flatMember));
        }
        public ActionResult Create(RentedBy rentedBy, string MobileNo)
        {
            var homes        = db.Homes.ToList();
            int HouseOwnerId = (int)Session["HouseOwnerId"];

            ViewBag.HomeId = homes.Where(a => a.HouseOwnerId == HouseOwnerId);
            List <HouseRepresentative> houseRepresentatives = db.HouseRepresentatives.ToList();
            HouseRepresentative        houseRepresentative  = houseRepresentatives.Find(a => a.MobileNo == MobileNo);


            if (houseRepresentative == null)
            {
                ViewBag.error = "There is No Representative with this Mobile No";
                return(View());
            }
            List <RentedBy> rentedBys            = db.RentedBys.ToList();
            RentedBy        HRForCheckRentedInfo = rentedBys.Find(a => a.HouseRepresentative == houseRepresentative.Id && a.LeavingDate == null);

            if (HRForCheckRentedInfo != null)
            {
                ViewBag.error = "This House Representaive Allready lives In A House!";
                return(View());
            }
            HRForCheckRentedInfo = rentedBys.Find(a => a.LeavingDate == null && a.FlatId == rentedBy.FlatId);
            if (HRForCheckRentedInfo != null)
            {
                ViewBag.error = "This House has Allready Occupied By Other!";
                return(View());
            }


            rentedBy.HouseRepresentative = houseRepresentative.Id;


            db.RentedBys.Add(rentedBy);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }