public override int Add(Vehicle inVehicle) { // This is just a demo And doesn't make much sense.. NoSql Tables typically should not have an Identity column .. They use Partition + Row Key as a composite... But in keeping with the Interface .. I'm simulating // Also The Make and Manufacturer should not accept special characters as they are part of the composite key VehicleTE vehInsert = Mapper.IMap.Map <VehicleTE>(inVehicle); /// if Make and Model exists then delete first VehicleTE existing = (VehicleTE)_Table.Execute(TableOperation.Retrieve <VehicleTE>(inVehicle.Manufacturer, inVehicle.Model)).Result; if (existing != null) { vehInsert.Id = existing.Id; _Table.Execute(TableOperation.Delete(existing)); } else { int newID = Convert.ToInt32(PersistedKeyValueHelper.GetValue(VehicleNoSqlRepository.AppName, VehicleNoSqlRepository.MaxIdKey)); newID++; PersistedKeyValueHelper.SaveValue(VehicleNoSqlRepository.AppName, VehicleNoSqlRepository.MaxIdKey, newID.ToString()); vehInsert.Id = newID; } _Table.Execute(TableOperation.Insert(vehInsert)); return(vehInsert.Id); }
public override bool Update(Vehicle vh) { bool retVal = false; VehicleTE existing = GetVTEByID(vh.Id); if (null != existing) { try { VehicleTE insertVte = Mapper.IMap.Map <VehicleTE>(vh); insertVte.Id = existing.Id; _Table.Execute(TableOperation.Delete(existing)); _Table.Execute(TableOperation.Insert(insertVte)); retVal = true; } catch { // Object does not exist } } return(retVal); }
public override Vehicle Get(int id) { Vehicle retVal = null; VehicleTE veh = GetVTEByID(id); if (null != veh) { retVal = Mapper.IMap.Map <Vehicle>(veh); } return(retVal); }
public override bool Delete(int id) { bool retVal = false; VehicleTE vte = GetVTEByID(id); ///vte = (VehicleTE)_Table.Execute(TableOperation.Retrieve<VehicleTE>(vte.Manufacturer, vte.Model)).Result; if (null != vte) { try { _Table.Execute(TableOperation.Delete(vte)); retVal = true; } catch (Exception ex) { Debug.WriteLine(ex.Message); // Object does not exist } } return(retVal); }