public ActionResult UpdateBrakes(MCTS_MNT.EntityDataModel.MNT_BAKE objBrake)
 {
     objMNTEntity.Entry <MCTS_MNT.EntityDataModel.MNT_BAKE>(objBrake).State = System.Data.Entity.EntityState.Modified;
     objMNTEntity.SaveChanges();
     return(RedirectToAction("MNTBrakes", "Home"));
 }
        public ActionResult AddBrakes(MCTS_MNT.EntityDataModel.MNT_BAKE objaddBrakes)
        {
            bool blnAddedBrakes = true;

            try
            {
                List <MNT_VEHICLE> lstRevVehicle = objMNTEntity.MNT_VEHICLE.Where(b => b.VEHICLE_NUMBER == objaddBrakes.BUS_NUMBER).ToList();
                //Error at :
                DateTime dtNullDate = Convert.ToDateTime("1/1/1901");
                MNT_BAKE lstBake    = objMNTEntity.MNT_BAKE.Where(c => c.BUS_NUMBER == objaddBrakes.BUS_NUMBER && c.DATE_BRAKE_OFF == dtNullDate && c.AXLE_POSITION == objaddBrakes.AXLE_POSITION).SingleOrDefault();
                MNT_BAKE lstNewBake = new MNT_BAKE();// objMNTEntity.MNT_BAKE.Where(c => c.BUS_NUMBER == objaddBrakes.BUS_NUMBER && c.DATE_BRAKE_OFF == dtNullDate && c.AXLE_POSITION == objaddBrakes.AXLE_POSITION).SingleOrDefault();
                if (lstRevVehicle.Count() > 0)
                {
                    if (lstBake != null && lstBake.BUS_NUMBER > 0)
                    {
                        try
                        {
                            lstNewBake.BUS_NUMBER        = lstBake.BUS_NUMBER;
                            lstNewBake.AXLE_POSITION     = lstBake.AXLE_POSITION;
                            lstNewBake.DATE_BRAKE_OFF    = objaddBrakes.DATE_BRAKE_ON is null || objaddBrakes.DATE_BRAKE_ON.ToString().Contains("01/01/0001") ? Convert.ToDateTime("1/1/1901"): (DateTime)objaddBrakes.DATE_BRAKE_ON;
                            lstNewBake.MILEAGE_BRAKE_OFF = objaddBrakes.MILEAGE_BRAKE_ON;
                            lstNewBake.DATE_BRAKE_ON     = lstBake.DATE_BRAKE_ON;
                            lstNewBake.MILEAGE_BRAKE_ON  = lstBake.MILEAGE_BRAKE_ON;
                            lstNewBake.GARAGE            = lstBake.GARAGE;
                            lstNewBake.BAKE_SIZE         = lstBake.BAKE_SIZE;
                            lstNewBake.BADGE_NUMBER_1    = lstBake.BADGE_NUMBER_1;
                            lstNewBake.BADGE_NUMBER_2    = lstBake.BADGE_NUMBER_2;
                            objMNTEntity.Entry <MCTS_MNT.EntityDataModel.MNT_BAKE>(lstNewBake).State = System.Data.Entity.EntityState.Added;
                            objMNTEntity.SaveChanges();

                            objMNTEntity.Entry <MCTS_MNT.EntityDataModel.MNT_BAKE>(lstBake).State = System.Data.Entity.EntityState.Deleted;
                            objMNTEntity.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            blnAddedBrakes = false;
                            //  return RedirectToAction("MNTBrakes", "Home");
                        }
                    }
                    if (blnAddedBrakes == true)
                    {
                        objaddBrakes.DATE_BRAKE_OFF = string.IsNullOrEmpty(objaddBrakes.DATE_BRAKE_OFF.ToString()) || objaddBrakes.DATE_BRAKE_OFF.ToString().Contains("1/1/0001") ? Convert.ToDateTime("1/1/1901") : objaddBrakes.DATE_BRAKE_OFF;
                        objMNTEntity.Entry <MCTS_MNT.EntityDataModel.MNT_BAKE>(objaddBrakes).State = System.Data.Entity.EntityState.Added;
                        objMNTEntity.SaveChanges();
                    }
                }
                else
                {
                    blnAddedBrakes = false;
                    return(RedirectToAction("MNTBrakes", "Home"));
                }
            }
            catch (Exception ex) { blnAddedBrakes = false; return(RedirectToAction("MNTBrakes", "Home")); }

            if (blnAddedBrakes == true)
            {
                return(RedirectToAction("MNTBrakes", "Home"));
            }
            else
            {
                return(RedirectToAction("MNTBrakes", "Home"));
            }
        }