public async Task CreateAsync(LogRideInformation logRideInformation) { try { _dbSet.Add(logRideInformation); await _context.SaveChangesAsync(); } catch (Exception ex) { LogError("There is error while updating LogRideInformation: " + ex.Message, ex); } }
public void Create(LogRideInformation logRideInformation) { try { _dbSet.Add(logRideInformation); _context.SaveChanges(); } catch (Exception ex) { LogError("There is error while updating LogRideInformation: " + ex.Message, ex); } }
public async Task DeleteAsync(LogRideInformation logRideInformation) { try { _cacheManager.Remove(String.Format(KeyForCacheYayYo, logRideInformation.Id)); _context.Database.ExecuteSqlCommand("DELETE LogRideInformation WHERE Id = @p0", logRideInformation.Id); await _context.SaveChangesAsync(); } catch (Exception ex) { LogError("There is error while updating data: " + ex.Message, ex); } }
public async Task UpdateAsync(LogRideInformation logRideInformation) { try { _cacheManager.Remove(String.Format(KeyForCacheYayYo, logRideInformation.Id)); //ref:http://patrickdesjardins.com/blog/entity-framework-ef-modifying-an-instance-that-is-already-in-the-context //A way to do it is to navigate inside the local of the DbSet to see if this one is there. If the entity is present, than you detach var local = _context.Set <LogRideInformation>() .Local .FirstOrDefault(f => f.Id == logRideInformation.Id); if (local != null) { _context.Entry(local).State = EntityState.Detached; } _context.Entry(logRideInformation).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (Exception ex) { LogError("There is error while updating LogRideInformation: " + ex.Message, ex); } }
public void Update(LogRideInformation logRideInformation) { try { _cacheManager.Remove(String.Format(KeyForCacheYayYo, logRideInformation.Id)); //ref:http://patrickdesjardins.com/blog/entity-framework-ef-modifying-an-instance-that-is-already-in-the-context //A way to do it is to navigate inside the local of the DbSet to see if this one is there. If the entity is present, than you detach var local = _context.Set <LogRideInformation>() .Local .FirstOrDefault(f => f.Id == logRideInformation.Id); if (local != null) { _context.Entry(local).State = EntityState.Detached; } _context.Entry(logRideInformation).State = EntityState.Modified; _context.SaveChanges(); } catch (Exception ex) { //Log the error (uncomment dex variable name and add a line here to write a log. //Trace.TraceError("There is error while updating data: " + dex.InnerException); LogError("There is error while updating LogRideInformation: " + ex.Message, ex); } }
public async Task <IHttpActionResult> ActiveSos(ActiveSosModel model) { //validate model if (!ModelState.IsValid) { foreach (var key in ModelState.Keys.Where(key => ModelState[key].Errors.Count > 0)) { return(BadRequest(ModelState[key].Errors[0].ErrorMessage)); } } //find safety settings var safetySetting = _safetySettingService.GetByYayYoId(model.YayYoId); try { if (safetySetting == null) { return(BadRequest("User does not exist")); } //update safety status safetySetting.Active = true; safetySetting.UpdatedOnUtc = DateTime.UtcNow; await _safetySettingService.UpdateAsync(safetySetting); //create new SOS ID var logSos = new LogSos { YayYoId = model.YayYoId, SafetySettingId = safetySetting.Id }; await _logSosService.CreateAsync(logSos); //get ride book info from YayYo var rideBookRequest = new GetLastestRideBookRequestModel { yayYo_id = model.YayYoId }; var rideBookReponse = _yayYoService.GetRideBook(rideBookRequest); if (rideBookReponse == null) { return(BadRequest("Error when get GetRideBook info")); } //add ride info to ride Information var rideBook = new LogRideInformation { DriverName = rideBookReponse.driver_name, CarMake = rideBookReponse.car_make, CarModel = rideBookReponse.car_model, CarColor = rideBookReponse.car_color, CarLicense = rideBookReponse.car_license, YayYoId = model.YayYoId, LocationPickup = rideBookReponse.pickup_location, TimeEta = rideBookReponse.time_eta, TimePickup = rideBookReponse.time_pickup, LocationDestination = rideBookReponse.destination_location, LogSosId = logSos.Id }; await _rideInformationService.CreateAsync(rideBook); //add SosGeolocation info var location = new LogSosGeolocation { LogSosId = logSos.Id, Location = model.GeoLocation }; await _sosGeolocationService.CreateAsync(location); //send SMS var contacts = await _contactService.GetBySafetySettingIdAsync(safetySetting.Id); foreach (var contact in contacts) { var contactInfo = new SmsRequestModel { FirstName = safetySetting.FirstName, RiderPickupLocation = rideBook.LocationPickup, DestinationAddress = rideBook.LocationDestination, RideScheduledTime = rideBook.TimePickup ?? DateTime.MinValue, GeolocationAddress = model.GeoLocation, ContactPhoneNumber = contact.Phone }; _yayYoService.SendSms(contactInfo); } return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }