public ActionResult EditDisc(Disc disc)
        {
            ManageDisc MD = new ManageDisc();

            if (ModelState.IsValid)
            {
                //TODO:cheack to see if there is any previous general discount (Allbra)
                if (disc.Allbra)
                {
                    if (MD.isAllbraActive()) //check to see if there is any previous all branches was clicked
                    {
                        IEnumerable <SelectListItem> braName = db.Branches.Select(
                            b => new SelectListItem {
                            Value = (b.Id).ToString(), Text = b.Name
                        });
                        ViewBag.Branches     = braName;
                        ViewBag.ErrorMessage = "Sorry There is General Discount added before!, please checkout the discount table for more information";
                        return(View(disc));
                    }
                    else
                    {
                        MD.DisableAll();          //here we are disabling all the previous dicount before adding the major discount
                                                  //if there is no previous all branche is clicked then
                        disc.Branche         = 0; // add 0 in brache filed to indicate that all branches was selected
                        db.Entry(disc).State = EntityState.Modified;
                        db.SaveChanges();
                        return(RedirectToAction("DiscList"));
                    }
                }


                if (MD.getBranchById(disc.Branche, disc.status, disc.Id)) //check to see if there is a branche with previous isActive equals true
                {
                    IEnumerable <SelectListItem> braName = db.Branches.Select(
                        b => new SelectListItem {
                        Value = (b.Id).ToString(), Text = b.Name
                    });
                    ViewBag.Branches     = braName;
                    ViewBag.ErrorMessage = "Sorry The branche is all ready has an active discount added before! or there is a grand dicount is active, please checkout the discount table for more information";
                    return(View(disc));
                }
                else
                {
                    if (disc.Branche == null)
                    {
                        disc.Branche = 0; //this makes sure that the 0 value stays in the branche column for the allbra is ture or false, otherise it will be remove and a null value will palce
                    }
                    db.Entry(disc).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("DiscList"));
                }


                //    //TODO:cheack to see if there is any previous general discount (Allbra)
                //    if (disc.Allbra)
                //    {
                //        if (MD.isAllbraActive()) //check to see if there is any previous all branches was clicked
                //        {
                //            IEnumerable<SelectListItem> braName = db.Branches.Select(
                //                b => new SelectListItem { Value = (b.Id).ToString(), Text = b.Name });
                //            ViewBag.Branches = braName;
                //            ViewBag.ErrorMessage = "Sorry There is General Discount added before!, please checkout the discount table for more information";
                //            return View(disc);
                //        }
                //        //if there is no previous all branche is clicked then
                //        disc.Branche = 0; // add 0 in brache filed to indicate that all branches was selected
                //    }
                //    db.Entry(disc).State = EntityState.Modified;
                //    db.SaveChanges();
                //    return RedirectToAction("DiscList");
            }
            return(View(disc));
        }
        public ActionResult AddDisc(Disc disc)
        {
            ManageDisc MD = new ManageDisc();

            if (ModelState.IsValid)
            {
                try
                {
                    //TODO:cheack to see if there is any previous general discount (Allbra)
                    if (disc.Allbra)
                    {
                        if (MD.isAllbraActive()) //check to see if there is any previous all branches was clicked
                        {
                            IEnumerable <SelectListItem> braName = db.Branches.Select(
                                b => new SelectListItem {
                                Value = (b.Id).ToString(), Text = b.Name
                            });
                            ViewBag.Branches     = braName;
                            ViewBag.ErrorMessage = "Sorry There is General Discount added before!, please checkout the discount table for more information";
                            return(View(disc));
                        }
                        MD.DisableAll(); //here we are disabling all the previous dicount before adding the major discount

                        //if there is no previous all branche is clicked then
                        disc.Branche = 0; // add 0 in brache filed to indicate that all branches was selected
                        db.Discs.Add(disc);
                        db.SaveChanges();
                        return(RedirectToAction("DiscList"));
                    }


                    if (MD.getBranchById(disc.Branche, disc.status)) //check to see if there is a branche with previous isActive equals true
                    {
                        IEnumerable <SelectListItem> braName = db.Branches.Select(
                            b => new SelectListItem {
                            Value = (b.Id).ToString(), Text = b.Name
                        });
                        ViewBag.Branches     = braName;
                        ViewBag.ErrorMessage = "Sorry The branche is all ready has an active discount added before!, please checkout the discount table for more information";
                        return(View(disc));
                    }
                    else
                    {
                        db.Discs.Add(disc);
                        db.SaveChanges();
                        return(RedirectToAction("DiscList"));
                    }
                }
                catch
                {
                    IEnumerable <SelectListItem> braName = db.Branches.Select(
                        b => new SelectListItem {
                        Value = (b.Id).ToString(), Text = b.Name
                    });
                    ViewBag.Branches = braName;
                    return(View(disc));
                }
            }
            else
            {
                //this is will run if the ModelState is Invalid
                IEnumerable <SelectListItem> braName = db.Branches.Select(
                    b => new SelectListItem {
                    Value = (b.Id).ToString(), Text = b.Name
                });
                ViewBag.Branches = braName;
                return(View(disc));
            }
        }