Ejemplo n.º 1
0
        public async Task <IHttpActionResult> PutToll(int id, Toll toll)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != toll.ID)
            {
                return(BadRequest());
            }

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TollExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> GetToll(int id)
        {
            Toll t = await db.Tolls.FindAsync(id);

            if (t == null)
            {
                return(NotFound());
            }

            TollDTO toll = new TollDTO
            {
                ID       = t.ID,
                Name     = t.Name,
                Location = t.Location,
                Vehicles = t.Vehicles.Select(v => new VehicleDTO()
                {
                    VehicleID   = v.VehicleID,
                    TollID      = v.TollID,
                    VehicleType = v.VehicleType,
                    Price       = v.Price
                }).ToList()
            };

            return(Ok(toll));
        }
Ejemplo n.º 3
0
 private void Awake()
 {
     playerGameObject    = FindObjectOfType <PlayerMove>().gameObject;
     UIScriptsGameObject = FindObjectOfType <InventoryUI>().gameObject; // InventoryUI & Shop scripts
     shopScript          = FindObjectOfType <Shop>();
     toll         = FindObjectOfType <Toll>();
     audio_source = GetComponent <AudioSource>();
 }
Ejemplo n.º 4
0
        public ActionResult DeleteConfirmed(int id)
        {
            Toll toll = db.Tolls.Find(id);

            db.Tolls.Remove(toll);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
 public ActionResult Edit([Bind(Include = "ID,Name,Location")] Toll toll)
 {
     if (ModelState.IsValid)
     {
         db.Entry(toll).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(toll));
 }
Ejemplo n.º 6
0
 public override string ToString()
 {
     return(@"Name: " + Name
            + "\nType: " + Type
            + "\nDirection: " + Direction
            + "\nSurface: " + Surface
            + "\nNumber of Lanes: " + NumberLanes.ToString()
            + "\nToll: " + Toll.ToString()
            + "\nParty: " + Party);
 }
Ejemplo n.º 7
0
        public ActionResult Create([Bind(Include = "ID,Name,Location")] Toll toll)
        {
            if (ModelState.IsValid)
            {
                db.Tolls.Add(toll);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(toll));
        }
Ejemplo n.º 8
0
        public async Task <IHttpActionResult> PostToll(Toll toll)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Tolls.Add(toll);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = toll.ID }, toll));
        }
Ejemplo n.º 9
0
        public async Task <IHttpActionResult> DeleteToll(int id)
        {
            Toll toll = await db.Tolls.FindAsync(id);

            if (toll == null)
            {
                return(NotFound());
            }

            db.Tolls.Remove(toll);
            await db.SaveChangesAsync();

            return(Ok(toll));
        }
Ejemplo n.º 10
0
        // GET: Tolls/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Toll toll = db.Tolls.Find(id);

            if (toll == null)
            {
                return(HttpNotFound());
            }
            return(View(toll));
        }
Ejemplo n.º 11
0
        public async Task <Result <Dictionary <int, Toll> > > GetToll()
        {
            HttpClient          client  = NetUtils.Instance();
            HttpResponseMessage respone = await client.GetAsync(NetURL.URL_TOLLS);

            ResponseResult         result = NetUtils.ExplainHttpResponce(respone);
            Dictionary <int, Toll> dict   = null;

            if (result.StateCode == 200)
            {
                JArray jArray = JArray.Parse(result.Data);
                dict = new Dictionary <int, Toll>();
                for (int i = 0; i < jArray.Count; i++)
                {
                    Toll toll = Toll.InstanceFormJson(jArray[i].ToString());
                    dict.Add(toll.Type, toll);
                }
            }
            return(Result <Dictionary <int, Toll> > .FromResponseResult(result, dict));
        }
Ejemplo n.º 12
0
        public ActionResult Put(int id, [FromBody] Toll value)
        {
            var toll = _context.Tolls.Find(id);

            if (toll != null)
            {
                try
                {
                    toll.date = value.date;
                    _context.SaveChanges();
                } catch (Exception e)
                {
                    return(new NotFoundObjectResult(new { success = false, message = "Error while updating!", errorMessage = e.Message }));
                }

                return(new OkObjectResult(new { success = true, message = "Toll updated" }));
            }
            else
            {
                return(new NotFoundObjectResult(new { success = false, message = "Toll not found with id", id = id }));
            }
        }
Ejemplo n.º 13
0
        public void LoadTollStations()
        {
            List <Toll>  auxTolls = new List <Toll>();
            StreamReader sr       = new StreamReader("../../../resources/EstacionesDePeaje.csv");
            string       line;

            sr.ReadLine(); // Skips first line of the csv file
            while ((line = sr.ReadLine()) != null)
            {
                string[] values      = line.Split(',');
                double   latitude    = ToDouble(Join(values[2].Split('.'), 1));
                double   longitude   = ToDouble(Join(values[3].Split('.'), 2));
                string   name        = values[4];
                string   description = values[5];
                string   updateDate  = values[6];
                int      price       = ToInteger(values[10]);
                Toll     t           = new Toll(latitude, longitude, name, description, updateDate, price);
                Console.WriteLine(latitude + ", " + longitude);
                auxTolls.Add(t);
            }
            TollStations = auxTolls;
        }
Ejemplo n.º 14
0
 public ActionResult Calculate(Toll t)
 {
     return(View(t));
 }