public ActionResult Create(NonWork nonWork)
        {
            var index        = db.BankBuildings.Max(x => x.id);
            var bankbuilding = db.BankBuildings.Find(index);

            if (ModelState.IsValid)
            {
                if (bankbuilding.CurrentPrices != null)
                {
                    if (nonWork.Prices > bankbuilding.CurrentPrices)
                    {
                        ViewBag.message = "السعر الذى ادخلته اكبر من الرصيد فى البنك";
                        ViewBag.BuildID = new SelectList(db.Buildings, "id", "buildName", nonWork.BuildID);
                        ViewBag.NonId   = new SelectList(db.NonWorksTables, "Id", "nonName", nonWork.NonId);
                        return(View(nonWork));
                    }
                }
                bankbuilding.CurrentPrices  -= nonWork.Prices;
                db.Entry(bankbuilding).State = EntityState.Modified;
                nonWork.Data = DateTime.Now;
                db.NonWorks.Add(nonWork);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.BuildID = new SelectList(db.Buildings, "id", "buildName", nonWork.BuildID);
            ViewBag.NonId   = new SelectList(db.NonWorksTables, "Id", "nonName", nonWork.NonId);
            return(View(nonWork));
        }
        public ActionResult Edit(NonWork nonWork)
        {
            if (ModelState.IsValid)
            {
                decimal?price = (decimal)Session["price"];
                if (nonWork.Prices != price)
                {
                    var index        = db.BankBuildings.Max(x => x.id);
                    var bankbuilding = db.BankBuildings.Find(index);
                    bankbuilding.CurrentPrices += price - nonWork.Prices;
                    if (bankbuilding.CurrentPrices < nonWork.Prices)
                    {
                        ViewBag.message = "السعر الذى ادخلته اكبر من الرصيد فى البنك";
                        ViewBag.BuildID = new SelectList(db.Buildings, "id", "buildName", nonWork.BuildID);
                        ViewBag.NonId   = new SelectList(db.NonWorksTables, "Id", "nonName", nonWork.NonId);
                        return(View(nonWork));
                    }
                }
                db.Entry(nonWork).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.BuildID = new SelectList(db.Buildings, "id", "buildName", nonWork.BuildID);
            ViewBag.NonId   = new SelectList(db.NonWorksTables, "Id", "nonName", nonWork.NonId);

            return(View(nonWork));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            NonWork nonWork = db.NonWorks.Find(id);

            db.NonWorks.Remove(nonWork);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: NonWorks/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            NonWork nonWork = db.NonWorks.Find(id);

            if (nonWork == null)
            {
                return(HttpNotFound());
            }
            return(View(nonWork));
        }
        // GET: NonWorks/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            NonWork nonWork = db.NonWorks.Find(id);

            if (nonWork == null)
            {
                return(HttpNotFound());
            }
            ViewBag.BuildID  = new SelectList(db.Buildings, "id", "buildName", nonWork.BuildID);
            ViewBag.NonId    = new SelectList(db.NonWorksTables, "Id", "nonName", nonWork.NonId);
            Session["price"] = nonWork.Prices;

            return(View(nonWork));
        }