// POST: /ListedOffence/Edit/5
        public void EditOffence(ListedOffence _offence)
        {
            //offences cannot be updated as they are referenced in the driving offence table.
            //Instead a new offence will be created and assigned the updated values.
            //The existing offence status will be set to false so it cannot be used
            //in new driving offences but can be accessed by existing driving offences.

            //create new offence
            ListedOffence _newOffence = new ListedOffence();
            //get existing offence from database
            ListedOffence _updatedOffence = _DAL.ListedOffenceFindById(_offence.Id);

            //assign new offence updated values of existing offence
            _newOffence.LoDesc = _offence.LoDesc.ToString();
            _newOffence.Lo28Days = _offence.Lo28Days;
            _newOffence.Lo56days = _offence.Lo56days;
            _newOffence.LoFine28 = _offence.LoFine28;
            _newOffence.LoFine56 = _offence.LoFine56;
            _newOffence.LoMandatoryCourtAppearance = _offence.LoMandatoryCourtAppearance;
            _newOffence.LoStatus = true;
            _newOffence.LoDateCreated = _offence.LoDateCreated;
            _newOffence.LoDateLastModified = System.DateTime.Now;
            //add new offence to database
            _DAL.CreateListedOffence(_newOffence);

            //Update status of existing offence to false
            //so it is not accessable to new driver offences
            //but is available to existing driver offences.
            _updatedOffence.LoStatus = false;
            _updatedOffence.LoDateLastModified = System.DateTime.Now;
            //Update database record of existing offence
            _DAL.EditListedOffence(_updatedOffence);
        }
 // cc - changed return type to int
 // public ListedOffence EditListedOffence(ListedOffence listedoffence)
 public int EditListedOffence(ListedOffence listedoffence)
 {
     db.Entry(listedoffence).State = EntityState.Modified;
        db.SaveChanges();
        //return null;
        return listedoffence.Id;
 }
 public ActionResult Create(ListedOffence listedoffence)
 {
     if (ModelState.IsValid)
     {
        // db.ListedOffences.Add(listedoffence);
        // db.SaveChanges();
        // return RedirectToAction("Index");
         ListedOffenceDAL dal = new ListedOffenceDAL();
         dal.CreateListedOffence(listedoffence);
         return RedirectToAction("Index");
     }
     return View(listedoffence);
 }
        /// <method>
        /// CreateOffence() inserts a new offence object into the database
        /// </method>
        public void CreateOffence(ListedOffence _newOffence)
        {
            _newOffence.LoDateCreated = System.DateTime.Now;
            _newOffence.LoDateLastModified = System.DateTime.Now;
            _newOffence.LoStatus = true;

            //CC - To do: check if mandatoryCourtAppearance/Description is set correctly
            //because required is not working on all fields.
            if (_newOffence.LoMandatoryCourtAppearance == true)
            {
                _newOffence.Lo28Days = 0;
                //_newOffence.Lo56days = 0;
                _newOffence.LoFine28 = 0;
                _newOffence.LoFine56 = 0;
            };

            _DAL.CreateListedOffence(_newOffence);
        }
 public ListedOffence CreateListedOffence(ListedOffence listedoffence)
 {
     db.ListedOffences.Add(listedoffence);
        db.SaveChanges();
        return null;
 }
        public ActionResult Edit(ListedOffence _offence)
        {
            //offences cannot be updated as they are referenced in the driving offence table.
            //Instead a offence will be create and assiged the value of the existing offence.
            //The exiting offence will have its status set to false so it cannot be used
            //in new driving offences but can be accessed by existing driving offences.
            List<SelectListItem> count = new List<SelectListItem>();

            //Define a driver offence status list
            count.Add(new SelectListItem
            {
                Text = "1",
                Value = "1",
                Selected = true
            });
            count.Add(new SelectListItem
            {
                Text = "2",
                Value = "2"
            });
            count.Add(new SelectListItem
            {
                Text = "3",
                Value = "3"
            });
            count.Add(new SelectListItem
            {
                Text = "4",
                Value = "4"
            });
            count.Add(new SelectListItem
            {
                Text = "5",
                Value = "5"
            });
            count.Add(new SelectListItem
            {
                Text = "6",
                Value = "6"
            });
            count.Add(new SelectListItem
            {
                Text = "7",
                Value = "7"
            });
            count.Add(new SelectListItem
            {
                Text = "8",
                Value = "8"
            });
            count.Add(new SelectListItem
            {
                Text = "9",
                Value = "9"
            });
            ViewData["count28days"] = new SelectList(count, "Value", "Text", _offence.Lo28Days);
            ViewData["count56days"] = new SelectList(count, "Value", "Text", _offence.Lo56days);

            if (ModelState.IsValid)
            {
                _BLL.EditOffence(_offence);
                return RedirectToAction("Index");
            }
            return View();
        }
        public ActionResult Create(ListedOffence _newOffence)
        {
            List<SelectListItem> count = new List<SelectListItem>();

            //Define a driver offence status list
            count.Add(new SelectListItem
            {
                Text = "1",
                Value = "1",
                Selected = true
            });
            count.Add(new SelectListItem
            {
                Text = "2",
                Value = "2"
            });
            count.Add(new SelectListItem
            {
                Text = "3",
                Value = "3"
            });
            count.Add(new SelectListItem
            {
                Text = "4",
                Value = "4"
            });
            count.Add(new SelectListItem
            {
                Text = "5",
                Value = "5"
            });
            count.Add(new SelectListItem
            {
                Text = "6",
                Value = "6"
            });
            count.Add(new SelectListItem
            {
                Text = "7",
                Value = "7"
            });
            count.Add(new SelectListItem
            {
                Text = "8",
                Value = "8"
            });
            count.Add(new SelectListItem
            {
                Text = "9",
                Value = "9"
            });
            ViewData["count"] = new SelectList(count, "Value", "Text");
            if (ModelState.IsValid)
            {
                // model is valid, save to db
                _BLL.CreateOffence(_newOffence);
                return RedirectToAction("Index");
            }

            // model is not valid
            return View(_newOffence);
        }
        public ActionResult Edit(ListedOffence listedoffence)
        {
            if (ModelState.IsValid)
            {
                 db.Entry(listedoffence).State = EntityState.Modified;
                //db.SaveChanges();
                //return RedirectToAction("Index");

                ListedOffenceDAL dal = new ListedOffenceDAL();
                dal.EditListedOffence(listedoffence);
                return RedirectToAction("Index");
            }
            return View(listedoffence);
        }
        public ActionResult Create(ListedOffence _newOffence)
        {
            if (ModelState.IsValid)
            {
                // model is valid, save to db
                _BLL.CreateOffence(_newOffence);
                return RedirectToAction("Index");
            }

            // model is not valid
            return View(_newOffence);
        }