/// <summary> /// Modify Guest for the mobile api /// </summary> /// <param name="guest">Guest object to update</param> public void Modify(Guest guest) { // Remove unwanted formatting before storing the Guest guest.RemoveFormattingFromPhoneNumbers(); var sbSqlStatement = new StringBuilder(); sbSqlStatement.Append("UPDATE Customer.Guest "); sbSqlStatement.Append("SET "); sbSqlStatement.Append(" TitleId = @TitleId, "); sbSqlStatement.Append(" Forename = @Forename, "); sbSqlStatement.Append(" Surname = @Surname, "); sbSqlStatement.Append(" AddressLine1 = @AddressLine1, "); sbSqlStatement.Append(" AddressLine2 = @AddressLine2, "); sbSqlStatement.Append(" AddressLine3 = @AddressLine3, "); sbSqlStatement.Append(" City = @City, "); sbSqlStatement.Append(" StateProvinceId = @StateProvinceId, "); sbSqlStatement.Append(" PostCode = @PostCode, "); sbSqlStatement.Append(" CountryId = @CountryId, "); sbSqlStatement.Append(" Email = @Email, "); sbSqlStatement.Append(" SourceOfEnquiryId = @SourceOfEnquiryId, "); sbSqlStatement.Append(" IsProviderAgreementAccepted = @IsProviderAgreementAccepted, "); sbSqlStatement.Append(" IsEviivoAgreementAccepted = @IsEviivoAgreementAccepted, "); sbSqlStatement.Append(" IsOtherAgreementAccepted = @IsOtherAgreementAccepted, "); sbSqlStatement.Append(" Notes = @Notes, "); sbSqlStatement.Append(" UpdatedByUserId = @UpdatedByUserId "); sbSqlStatement.Append("WHERE "); sbSqlStatement.Append(" Id = @Id AND "); sbSqlStatement.Append(" BusinessId = @BusinessId; "); // Update the Guest var parameters = new List<SqlParameter> { DbHelper.CreateParameter(GuestMapper.Parameters.Id, guest.Id), DbHelper.CreateParameter(GuestMapper.Parameters.BusinessId, guest.BusinessId), DbHelper.CreateParameter(GuestMapper.Parameters.TitleId, guest.TitleId), DbHelper.CreateParameter(GuestMapper.Parameters.Forename, guest.Forename), DbHelper.CreateParameter(GuestMapper.Parameters.Surname, guest.Surname), DbHelper.CreateParameter(GuestMapper.Parameters.AddressLine1, guest.AddressLine1), DbHelper.CreateParameter(GuestMapper.Parameters.AddressLine2, guest.AddressLine2), DbHelper.CreateParameter(GuestMapper.Parameters.AddressLine3, guest.AddressLine3), DbHelper.CreateParameter(GuestMapper.Parameters.City, guest.City), DbHelper.CreateParameter(GuestMapper.Parameters.StateProvinceId, guest.StateProvinceId), DbHelper.CreateParameter(GuestMapper.Parameters.PostCode, guest.PostCode), DbHelper.CreateParameter(GuestMapper.Parameters.CountryId, guest.CountryId), DbHelper.CreateParameter(GuestMapper.Parameters.Email, guest.Email), DbHelper.CreateParameter(GuestMapper.Parameters.SourceOfEnquiryId, guest.SourceOfEnquiryId), DbHelper.CreateParameter(GuestMapper.Parameters.IsProviderAgreementAccepted, guest.IsProviderAgreementAccepted), DbHelper.CreateParameter(GuestMapper.Parameters.IsEviivoAgreementAccepted, guest.IsEviivoAgreementAccepted), DbHelper.CreateParameter(GuestMapper.Parameters.IsOtherAgreementAccepted, guest.IsOtherAgreementAccepted), DbHelper.CreateParameter(GuestMapper.Parameters.Notes, guest.Notes), DbHelper.CreateParameter(GuestPhoneMapper.Parameters.GuestId, guest.Id), }; // Add auditing parameters AuditFieldsHelper.PopulateAuditFields(parameters); int rowsAffected = DbHelper.ExecuteNonQueryCommand(sbSqlStatement.ToString(), parameters: parameters); // Check if the update was successful and return if (rowsAffected == 0) { throw new ExpectedResultException(ErrorFactory.CreateAndLogError(Errors.SRVEX30027, "GuestDao.Modify", additionalDescriptionParameters: (new object[] { guest.GetType().Name, guest.Id }), arguments: new object[] { guest.GetType().Name, guest.Id })); } // Modify Phones : Remove and Insert Phones guestPhoneDao.RemoveAllByGuestId(guest.Id.Value); foreach (var guestPhone in guest.GuestPhones) { guestPhoneDao.Create(guestPhone, guest.Id.Value); } }
public object GetSortingProp(Guest guest) { PropertyInfo property = guest.GetType().GetProperties().FirstOrDefault(prop => prop.Name == cols[sortIndex]); return property.GetValue(guest, null); }