public IHttpActionResult PutTruckLocation(int id, TruckLocation truckLocation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != truckLocation.id) { return(BadRequest()); } db.Entry(truckLocation).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TruckLocationExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public bool AddTruckDriver(TruckDriver truckDriver) { if (truckDriver == null) { return(false); } _context.TruckDrivers.Add(truckDriver); TruckLocation truckLocation = new TruckLocation { TruckDriverId = truckDriver.TruckDriverId, }; _context.TruckLocations.Add(truckLocation); TruckDriverDocument truckDriverDocument = new TruckDriverDocument { TruckDriverId = truckDriver.TruckDriverId }; _context.TruckDriverDocuments.Add(truckDriverDocument); _context.SaveChanges(); return(true); }
public IHttpActionResult UpdateTruckLocation(int truckDriverId, TruckLocation truckLocation) { if (truckLocation == null || truckLocation.TruckDriverId != truckDriverId) { return(BadRequest()); } var findTruckLocationByTruckDriverId = _truckLocationRepository.GetTruckLocationByTruckDriverId(truckDriverId); if (findTruckLocationByTruckDriverId == null) { return(NotFound()); } string requestUri = string.Format(baseUri, truckLocation.Latitude, truckLocation.Longitude); using (var wc = new WebClient()) { string result = wc.DownloadString(requestUri); var xmlElm = XElement.Parse(result); var status = (from elm in xmlElm.Descendants() where elm.Name == "status" select elm).FirstOrDefault(); if (status.Value.ToLower() == "ok") { var res = (from elm in xmlElm.Descendants() where elm.Name == "formatted_address" select elm).FirstOrDefault(); findTruckLocationByTruckDriverId.TruckCurrentAddress = res.Value.ToString(); if (res != null) { requestUri = res.Value; } } } findTruckLocationByTruckDriverId.Latitude = truckLocation.Latitude; findTruckLocationByTruckDriverId.Longitude = truckLocation.Longitude; // DateTime dateTime = DateTime.UtcNow; var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time"); var convertedTime = TimeZoneInfo.ConvertTime(dateTime, timeZoneInfo); findTruckLocationByTruckDriverId.TruckCurrentTime = convertedTime; var updateTruckLocation = _truckLocationRepository.UpdateTruckLocation(findTruckLocationByTruckDriverId); if (updateTruckLocation.Equals(false)) { return(Ok(false)); } return(Ok(true)); }
public IHttpActionResult GetTruckLocation(int id) { TruckLocation truckLocation = db.TruckLocations.Find(id); if (truckLocation == null) { return(NotFound()); } return(Ok(truckLocation)); }
public IHttpActionResult PostTruckLocation(TruckLocation truckLocation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.TruckLocations.Add(truckLocation); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = truckLocation.id }, truckLocation)); }
public bool UpdateTruckLocation(TruckLocation truckLocation) { if (truckLocation == null) { return(false); } _context.Entry(truckLocation).State = EntityState.Modified; _context.SaveChanges(); return(true); }
public IHttpActionResult DeleteTruckLocation(int id) { TruckLocation truckLocation = db.TruckLocations.Find(id); if (truckLocation == null) { return(NotFound()); } db.TruckLocations.Remove(truckLocation); db.SaveChanges(); return(Ok(truckLocation)); }