Ejemplo n.º 1
0
        public IHttpActionResult PuttblvelogCours(int id, tblvelogCours tblvelogCours)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tblvelogCours.Id)
            {
                return(BadRequest());
            }

            db.Entry(tblvelogCours).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tblvelogCoursExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        public IHttpActionResult PutVeLogData(int id, VeLogData veLogData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != veLogData.Id)
            {
                return(BadRequest());
            }

            db.Entry(veLogData).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VeLogDataExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 3
0
        public ActionResult Create([Bind(Include = "Id,Username,Password,Role")] tblvelogUser tblvelogUser)
        {
            if (ModelState.IsValid)
            {
                db.tblvelogUsers.Add(tblvelogUser);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tblvelogUser));
        }
Ejemplo n.º 4
0
        public ActionResult Create(VeLogDataView VeLogDataRec)
        {
            VelogDataContext dbContext = new VelogDataContext();

            int             maxId;
            VeLogDataClient VC = new VeLogDataClient();



            if (dbContext.VeLogDatas.Any())

            {
                maxId = dbContext.VeLogDatas.Max(item => item.Id);
            }
            else
            {
                maxId = 0;
            }

            if (ModelState.IsValid)
            {
                Double MileageAvg = VeLogDataRec.EndMileage - VeLogDataRec.StartMileage;
                if (VeLogDataRec.LocationList != null)
                {
                    MileageAvg = MileageAvg / (VeLogDataRec.LocationList.Count() + 1);
                }

                VeLogData DataToSubmit = new VeLogData();

                DataToSubmit.Comment = VeLogDataRec.Comment;

                DataToSubmit.CreationDate = DateTime.Now;;
                DataToSubmit.Distance     = MileageAvg;

                DataToSubmit.DriverName   = VeLogDataRec.DriverName;
                DataToSubmit.EndMileage   = VeLogDataRec.EndMileage;
                DataToSubmit.StartMileage = VeLogDataRec.StartMileage;
                DataToSubmit.VehicleRego  = VeLogDataRec.VehicleRego;
                DataToSubmit.TripId       = VeLogDataRec.VehicleRego + "--" + maxId;
                DataToSubmit.Campus       = VeLogDataRec.Campus;
                DataToSubmit.Division     = VeLogDataRec.Division;
                DataToSubmit.Course       = VeLogDataRec.Course;

                // VC.Create(DataToSubmit);
                dbContext.VeLogDatas.Add(DataToSubmit);
                dbContext.SaveChanges();

                if (VeLogDataRec.LocationList != null)
                {
                    for (int i = 0; i < VeLogDataRec.LocationList.Count(); i++)
                    {
                        VeLogData DataToSubmit1 = new VeLogData();

                        DataToSubmit1.Comment = VeLogDataRec.Comment;

                        DataToSubmit1.CreationDate = DateTime.Now;;
                        DataToSubmit1.Distance     = MileageAvg;

                        DataToSubmit1.DriverName   = VeLogDataRec.DriverName;
                        DataToSubmit1.EndMileage   = VeLogDataRec.EndMileage;
                        DataToSubmit1.StartMileage = VeLogDataRec.StartMileage;
                        DataToSubmit1.VehicleRego  = VeLogDataRec.VehicleRego;
                        DataToSubmit1.TripId       = VeLogDataRec.VehicleRego + "--" + maxId;
                        DataToSubmit1.Campus       = VeLogDataRec.LocationList[i].Campus;
                        DataToSubmit1.Division     = VeLogDataRec.LocationList[i].Division;
                        DataToSubmit1.Course       = VeLogDataRec.LocationList[i].Course;
                        dbContext.VeLogDatas.Add(DataToSubmit1);
                        dbContext.SaveChanges();
                        //VC.Create(DataToSubmit1);
                    }
                }

                return(RedirectToAction("Create", new { message = "Mileage Details added successfully!!!" }));
            }

            else
            {
                ViewBag.Division    = new SelectList(dbContext.tblvelogDivisions, "Division", "Division");
                ViewBag.Course      = new SelectList(dbContext.tblvelogCourses, "Courses", "Courses");
                ViewBag.Campus      = new SelectList(dbContext.tblvelogCampus, "Campus", "Campus");
                ViewBag.VehicleRego = new SelectList(dbContext.tblVelogCars, "Registration", "Registration");


                if (VeLogDataRec.VehicleRego != null)
                {
                    tblVelogCar rec = dbContext.tblVelogCars.First(x => x.Registration == VeLogDataRec.VehicleRego);
                    VeLogDataRec.MakeCmb = rec.Model + "--" + rec.Make + "--" + rec.Colour;
                }


                return(View("Create", VeLogDataRec));
            }
        }