예제 #1
0
 public ActionResult Edit(Car car)
 {
     if (ModelState.IsValid)
     {
         db.Cars.Attach(car);
         db.ObjectStateManager.ChangeObjectState(car, EntityState.Modified);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "Name", car.CustomerID);
     return View(car);
 }
예제 #2
0
    public ActionResult Create(Car car)
    {
        if (ModelState.IsValid)
        {
            db.Cars.AddObject(car);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "Name", car.CustomerID);
        return View(car);
    }
예제 #3
0
 /// <summary>
 /// Create a new Car object.
 /// </summary>
 /// <param name="customerID">Initial value of the CustomerID property.</param>
 /// <param name="carID">Initial value of the CarID property.</param>
 public static Car CreateCar(global::System.Int64 customerID, global::System.Int64 carID)
 {
     Car car = new Car();
     car.CustomerID = customerID;
     car.CarID = carID;
     return car;
 }
예제 #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Cars EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCars(Car car)
 {
     base.AddObject("Cars", car);
 }
예제 #5
0
    public void DownloadInfo(HttpContextBase httpContext,string xmlUrl, string stationID, bool start=true)
    {
        try
        {

            Station station;
            Customer customer;
            Car car;

            StreamReader reader = new StreamReader(WebRequest.Create(xmlUrl).GetResponse().GetResponseStream());
            XmlSerializer xSerializer = new XmlSerializer(typeof(proton));
            proton greenlotsInfo = (proton)xSerializer.Deserialize(reader);

            if(db.Stations.Where(s=>s.UniqueID==stationID).Count() <=0)
            {
                station = new Station {UniqueID = stationID};
                db.Stations.AddObject(station);
                db.SaveChanges();
            }
            else
            {
                station = db.Stations.Where(s => s.UniqueID.Trim() == stationID.Trim()).FirstOrDefault();

            }



            string path = httpContext.Server.MapPath("~/Logs/GreenLots/" + "log.txt");



            if (station != null)
            {
                station.Name = greenlotsInfo.Location.information[0].name;
                station.Address = greenlotsInfo.Location.information[0].address + "\n" + greenlotsInfo.Location.information[0].address1 + "\n" + greenlotsInfo.Location.information[0].address2;
                station.PostalCode = greenlotsInfo.Location.information[0].postal;
                try
                {
                    station.Rate = Convert.ToDouble( greenlotsInfo.Location.information[0].rate);
                }
                catch(Exception ex)
                {

                }
            }

            var customerInfo = greenlotsInfo.User.information[0];
            if (db.Customers.Where(s => s.Email == customerInfo.email).Count() <= 0)
            {
                customer = new Customer();
                customer.Email = greenlotsInfo.User.information[0].email;
                db.Customers.AddObject(customer);
                db.SaveChanges();
            }
            else
            {
                customer = db.Customers.Where(s => s.Email == customerInfo.email).FirstOrDefault();
            }

            if (customer != null)
            {
                customer.Picture = customerInfo.image;
                customer.Name = customerInfo.firstname + " " + customerInfo.lastname;
                customer.Address = customerInfo.address + " " + customerInfo.address1 + " " + customerInfo.address2;
                customer.Language = customerInfo.language;
                customer.SMSAlert =customerInfo.sms_alert=="1";
                customer.EmailAlert =customerInfo.email_alert=="1";
                customer.Phone = customerInfo.contact;
                customer.Balance = customerInfo.credit_balance;
            }


            var carInfo = greenlotsInfo.Vehicle.information[0];
            var history = greenlotsInfo.History.session[0];
            if (db.Cars.Where(s => s.RFID == carInfo.rfid).Count() <= 0)
            {
                car = new Car();
                car.RFID = carInfo.rfid;
                if (customer != null)
                    car.CustomerID = customer.CustomerID;
                db.Cars.AddObject(car);
                db.SaveChanges();
            }
            else
            {
                car = db.Cars.Where(s => s.RFID == carInfo.rfid).FirstOrDefault();
            }

            if (car != null)
            {
                car.License = carInfo.license_plate;
                car.Make = carInfo.make;
                car.Model = carInfo.model;
                try
                {
                    car.TotalUsage = Convert.ToDouble(carInfo.total_usage);
                    car.BatteryCycle = Convert.ToDouble(carInfo.battery_cycle);
                }
                catch(Exception ex)
                {

                }
                //Fix up date
                var datetxt = history.end;
                try
                {
                    datetxt = datetxt.Replace("Today", DateTime.Now.Date.ToShortDateString());
                    datetxt = datetxt.Replace("Yesterday", DateTime.Now.Date.ToShortDateString());
                    car.LastRechargeDate = DateTime.Parse(datetxt);
                }
                catch (Exception ex)
                {
                    try
                    {
                        DateTime.ParseExact(datetxt, "dd/MM/yyyy HH:mm", null);
                    }
                    catch(Exception ex1)
                    {

                        Logger.WriteLine(path, "\nInvalid Date Format Detected");
                    }

                }


            }



            Logger.WriteLine(path, "\n--------------- Data Received  ---------------");
            Logger.WriteLine(path, (string) greenlotsInfo.User.information[0].address);
            //   Logger.WriteLine(path, greenlotsInfo.email);
            Logger.WriteLine(path, "\n--------------- Data Received End---------------");

            db.SaveChanges();

            if (start)
            {
                if (station != null && car!=null)
                    Service.MakeStationUnAvailable(station.StationID, car.RFID);
            }
            else
            {
                if (station != null)
                    Service.MakeStationAvailable(station.StationID);
            }
        }
        catch (Exception)
        {

            throw;
        }
    }