/// <summary> /// Writes the specified record. /// </summary> /// <param name="record">The record.</param> /// <exception cref="System.ArgumentNullException">record</exception> /// <exception cref="RecorderException">Cannot write the record.</exception> public void Write(Record record) { if (record == null) throw new ArgumentNullException("record"); try { RecordAppService.AddRecord(record); } catch (Exception ex) { throw new RecorderException("Cannot write the record.", ex); } }
public void Add(object pObj, int pOperation,object pOldObj=null) { var newRecorder = new Record(); newRecorder.SessionId = GetHashCode().ToString(); newRecorder.StartDate = DateTime.Now; if (pOperation > 2) newRecorder.UserId = HealthAuthentication.SessionInfo.UserId; newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("IP", GetServerIPAddress())); newRecorder.OperationName = ConfigurationManager.AppSettings[pOperation.ToString(CultureInfo.InvariantCulture)].ToString(CultureInfo.InvariantCulture); switch (pOperation) { case 1: var login = (User)pObj; newRecorder.UserId = login.UserId; break; case 2: var userBloq = (User)pObj; newRecorder.UserId = userBloq.UserId; break; #region GeoCity case 3: var newCity = (GeoCity)pObj; newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("GeoCityId", newCity.GeoCityId)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("GeoStateId", newCity.GeoStateId)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("Name", newCity.Name)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("Latitude", newCity.Latitude.ToString())); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("Longitude", newCity.Longitude.ToString())); break; case 4: var city = (GeoCity)pObj; newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueGeoCityId", city.GeoCityId)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueGeoStateId", city.GeoStateId)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueLatitude", city.Latitude.ToString())); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueLongitude", city.Longitude.ToString())); break; case 5: var geoCityId = (string)pObj; newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("GeoCityId", geoCityId)); break; #endregion #region GeoCountry case 6: var newCountry = (GeoCountry)pObj; newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("GeoCountryId", newCountry.GeoCountryId)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("Name", newCountry.Name)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("Latitude", newCountry.Latitude.ToString())); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("Longitude", newCountry.Longitude.ToString())); break; case 7: var country = (GeoCountry)pObj; newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueGeoCityId", country.GeoCountryId)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueName", country.Name)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueLatitude", country.Latitude.ToString())); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueLongitude", country.Longitude.ToString())); break; case 8: var geoCountryId = (string)pObj; newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("GeoCountryId", geoCountryId)); break; #endregion #region GeoState case 9: var newState = (GeoState)pObj; newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("GeoCountryId", newState.GeoCountryId)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("GeoStateId", newState.GeoStateId)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("Name", newState.Name)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("Latitude", newState.Latitude.ToString())); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("Longitude", newState.Longitude.ToString())); break; case 10: var state = (GeoState)pObj; newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueGeoCountryId", state.GeoCountryId)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueGeoStateId", state.GeoStateId)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueName", state.Name)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueLatitude", state.Latitude.ToString())); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueLongitude", state.Longitude.ToString())); break; case 11: var geoStateId = (string)pObj; newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("GeoStateId", geoStateId)); break; #endregion #region Employee case 36: var newEmpleado = (Employee)pObj; newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("EmployeeId", newEmpleado.EmployeeId.ToString())); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("FullName", newEmpleado.FullName)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("Phone", (newEmpleado.Phone != null ? newEmpleado.Phone.ToString() : string.Empty))); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("Mobile", (newEmpleado.Mobile != null ? newEmpleado.Mobile.ToString() : string.Empty))); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("EMail", newEmpleado.EMail)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("UserId", newEmpleado.UserId.ToString())); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("Photo", newEmpleado.Photo)); break; case 37: var empleado = (Employee)pObj; newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueEmployeeId", empleado.EmployeeId.ToString())); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueFullName", empleado.FullName)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValuePhone", (empleado.Phone != null ? empleado.Phone.ToString() : string.Empty))); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueMobile", (empleado.Mobile != null ? empleado.Mobile.ToString() : string.Empty))); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueEMail", empleado.EMail)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueUserId", empleado.UserId.ToString())); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValuePhoto", (empleado.Photo != null ? empleado.Photo.ToString() : string.Empty))); break; case 38: var employeeId = ((int)pObj).ToString(); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("EmployeeId", employeeId)); break; #endregion #region User case 39: var newUser = (User)pObj; newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("UserId", newUser.UserId.ToString())); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("UserName", newUser.UserName)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("UserStateId", newUser.UserStateId.ToString())); break; case 40: var user = (User)pObj; newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueUserId", user.UserId.ToString())); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueUserName", user.UserName)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueUserStateId", user.UserStateId.ToString())); break; case 41 : var userId = ((int)pObj).ToString(); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("UserId", userId)); break; case 42: var userRole = (UserRole)pObj; newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueUserId", userRole.UserId.ToString())); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueUserName", userRole.UserRoleId.ToString())); break; #endregion #region Setting case 43: var newSetting = (Setting)pObj; newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("SettingId", newSetting.SettingId.ToString())); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("Name", newSetting.Name)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("Value", (newSetting.Value != null ? newSetting.Value.ToString() : string.Empty))); break; case 44: var setting = (Setting)pObj; newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueSettingId", setting.SettingId.ToString())); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueName", setting.Name)); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("newValueValue", (setting.Value != null ? setting.Value.ToString() : string.Empty))); break; case 45: var settingId = ((int)pObj).ToString(); newRecorder.Parameters.Add(new Health.Data.KeyValuePair<string, string>("SettingId", settingId)); break; #endregion } Health.Recorder.Recorder.Instance.Write(newRecorder); }