public ActionResult Edit(Customer customer) { if (ModelState.IsValid) { db.Customers.Attach(customer); db.ObjectStateManager.ChangeObjectState(customer, EntityState.Modified); db.SaveChanges(); return RedirectToAction("Index"); } return View(customer); }
public ActionResult Create(Customer customer) { if (ModelState.IsValid) { db.Customers.AddObject(customer); db.SaveChanges(); return RedirectToAction("Index"); } return View(customer); }
/// <summary> /// Deprecated Method for adding a new object to the Customers EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCustomers(Customer customer) { base.AddObject("Customers", customer); }
/// <summary> /// Create a new Customer object. /// </summary> /// <param name="customerID">Initial value of the CustomerID property.</param> public static Customer CreateCustomer(global::System.Int64 customerID) { Customer customer = new Customer(); customer.CustomerID = customerID; return customer; }
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; } }